lundi 25 janvier 2016

How to Handle Response Validator Laravel in Android using Retrofit

I have response error(default validator message Laravel) like this:

{
  "email": [
    "The email has already been taken."
  ],
  "no_hp": [
    "The no hp field is required."
  ],
  "type": [
    "The type field is required."
  ]
}

I getting error with code:

RestClient.get().register(name, email, password, nohp, type).enqueue(new Callback<Register>() {
            @Override
            public void onResponse(Response<Register> response) {
                hideDialog();
                // success!
                if (response.isSuccess()) {
                    // request successful (status code 200, 201)
                    Register register = response.body();

                    String email = register.getEmail();
                    Log.d("Respon", "Respon: "+email);
                } else {
                    // response received but request not successful (like 400,401,403 etc)
                    //Handle errors
                    Register register = response.body();

                    String email = register.getEmail();
                    Log.d("Respon", "Responnya: "+email);
                }
            }

            @Override
            public void onFailure(Throwable t) {
                Log.d("Respon", "Error");
                hideDialog();
            }
        });
    }

Register is object which in name, email, password, etc..

How to handle response it?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire