O Android Volley error.getMessage () está em branco
Então, eu estou fazendo um POST JSonObjectRequest no meu servidor e, quando é bem-sucedido, tudo funciona e as informações são postadas, mas se houver um erro e eu tentar exibi-lo em um brinde, ele aparecerá em branco. Aqui está o meu pedido:
private void logUserIn() {
final String URL = Globals.BASE_URL +"/auth/login/";
// Post params to be sent to the server
HashMap<String, String> params = new HashMap<String, String>();
params.put("username", username.getText().toString());
params.put("password", password.getText().toString());
JsonObjectRequest req = new JsonObjectRequest(URL, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
Log.d("Log In User", response.toString());
//logged in db, changes screens
Intent nextScreen = new Intent(getApplicationContext(), MyProfile.class);
startActivity(nextScreen);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_SHORT).show();
VolleyLog.e("Error: ", error.getMessage());
}
});
// add the request object to the queue to be executed
Globals.mRequestQueue.add(req);
}
error.getMessage () está sempre em branco. Aqui está minha resposta (testada usando CURL) quando o servidor retorna um erro:
{"non_field_errors": ["Não foi possível fazer o login com as credenciais fornecidas." ]}
Não consigo imprimir esta mensagem. o que estou perdendo? O POST funciona, mas a resposta do erro está sendo exibida em branco ...