<commit_before>package com.humbughq.mobile;

import org.apache.http.HttpStatus;
import org.apache.http.client.HttpResponseException;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import android.widget.TextView;

class AsyncLogin extends HumbugAsyncPushTask {
    LoginActivity context;

    public AsyncLogin(LoginActivity loginActivity, String username,
            String password) {
        super(loginActivity.app);
        context = loginActivity;
        // Knowing your name would be nice, but we don't use it anywhere and
        // it's not returned by the API, so having it be null here is fine for
        // now.
        this.app.setEmail(username);
        this.setProperty("username", username);
        this.setProperty("password", password);
    }

    public final void execute() {
        execute("POST", "v1/fetch_api_key");
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);

        if (result != null) {
            try {
                JSONObject obj = new JSONObject(result);

                if (obj.getString("result").equals("success")) {
                    this.app.setLoggedInApiKey(obj.getString("api_key"));
                    this.context.openHome();
                    callback.onTaskComplete(result);

                    return;
                }
            } catch (JSONException e) {
                ZLog.logException(e);
            }
        }
        TextView errorText = (TextView) this.context
                .findViewById(R.id.error_text);
        errorText.setText("Unknown error");
        Log.wtf("login", "We shouldn't have gotten this far.");
    }

    @Override
    protected void handleHTTPError(final HttpResponseException e) {
        final TextView errorText = (TextView) this.context
                .findViewById(R.id.error_text);
        if (e.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
            errorText.post(new Runnable() {
                @Override
                public void run() {
                    errorText.setText("Incorrect username or password");
                }
            });
            this.cancel(true);
        } else {
            errorText.post(new Runnable() {
                @Override
                public void run() {
                    errorText.setText("Unknown error");
                }
            });
            // supermethod invokes cancel for us
            super.handleHTTPError(e);
        }
    }
}<commit_msg>More descriptive login error message<commit_after>package com.humbughq.mobile;

import org.apache.http.HttpStatus;
import org.apache.http.client.HttpResponseException;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;
import android.widget.TextView;

class AsyncLogin extends HumbugAsyncPushTask {
    LoginActivity context;

    public AsyncLogin(LoginActivity loginActivity, String username,
            String password) {
        super(loginActivity.app);
        context = loginActivity;
        // Knowing your name would be nice, but we don't use it anywhere and
        // it's not returned by the API, so having it be null here is fine for
        // now.
        this.app.setEmail(username);
        this.setProperty("username", username);
        this.setProperty("password", password);
    }

    public final void execute() {
        execute("POST", "v1/fetch_api_key");
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);

        if (result != null) {
            try {
                JSONObject obj = new JSONObject(result);

                if (obj.getString("result").equals("success")) {
                    this.app.setLoggedInApiKey(obj.getString("api_key"));
                    this.context.openHome();
                    callback.onTaskComplete(result);

                    return;
                }
            } catch (JSONException e) {
                ZLog.logException(e);
            }
        }
        TextView errorText = (TextView) this.context
                .findViewById(R.id.error_text);
        errorText.setText("Unknown error");
        Log.wtf("login", "We shouldn't have gotten this far.");
    }

    @Override
    protected void handleHTTPError(final HttpResponseException e) {
        final TextView errorText = (TextView) this.context
                .findViewById(R.id.error_text);
        if (e.getStatusCode() == HttpStatus.SC_FORBIDDEN) {
            errorText.post(new Runnable() {
                @Override
                public void run() {
                    errorText.setText("Incorrect username or password");
                }
            });
            this.cancel(true);
        } else {
            errorText.post(new Runnable() {
                @Override
                public void run() {
                    errorText.setText("Network error");
                }
            });
            // supermethod invokes cancel for us
            super.handleHTTPError(e);
        }
    }
}
{'fraction_non_alphanumeric': 0.09867771857114664, 'fraction_numerical': 0.00039471087428458656, 'mean_word_length': 1.8108707709373266, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3210919', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1261, 'n_words': 302}