I am doing some http connection trough android and server in nodejs, and in my server i have some error handling for diferent status code, what i need is to get the related message specific for the behaviour im doing.
Imagine i have some username unique error handling, if i put the same username i want to retrive the message that i already have for user handling in the server.
so my code is like this at the moment:` public void register(View view) { //defining form data
String username = usernameTxt.getText().toString();
String password = passwordTxt.getText().toString();
String email = emailTxt.getText().toString();
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("email", email);
params.put("password", password);
JsonObjectRequest request = new JsonObjectRequest(URL, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d("response",String.valueOf(response));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null && networkResponse.statusCode == 400) {
Log.d("fail","fail");
}
}
});
request.setRetryPolicy(new DefaultRetryPolicy(60000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
queue.add(request);
}`
i can already handle the status code, but how to retrive the message for the specific error?
via Cris dois
No comments:
Post a Comment