wadjaafar / CashQ

1 stars 1 forks source link

Errors handling #1

Open adonese opened 5 years ago

adonese commented 5 years ago

So, I wanted to work on the error handling part, currently it is quite messy (both on my part and yours).

public void onError(ANError error) {
                // handle error
                progressDialog.dismiss();
                AlertDialog.Builder builder = new AlertDialog.Builder(SignUpActivity.this);
                builder.setTitle("Failed")
                        .setMessage("Something went wrong, please try again!")
                        .setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {

Here is what currently the case in the backend, we have two types of error responses:

  1. EBS errors {"details": object, "message": string} // i omitted other parts
  2. validation errors the same as EBS errors
  3. other errors, which is usually about authentication, etc (umm non-payment errors) {"code": "some_error", "message": "a description of this error, usually a human friendly format"}

My proposal is like this:

a method somewhere that converts the error.getErrorBody() to a class that has code and message fields (and they are both of type string)

adonese commented 5 years ago

I will refine this one later-- it is now code and message, but it should be rather errorCode and errorMessage, and also bear in mind that, this is different from http status code.

Any thoughts?