JSONObject jsonResponse = new JSONObject(response.getData());
if(jsonResponse.has("message")) {
if(jsonResponse.getString("message").equals("Invalid username or password")) {
return new APITatarWrongCredentialsException();
}
return new APITatarException(jsonResponse.getString("message"));
} else if(jsonResponse.has("error") && jsonResponse.getJSONObject("error").has("type") && jsonResponse.getJSONObject("error").getString("type").equals("api_user_authorization_failed")) {
return new APITatarUnauthorizationException();
} else if(jsonResponse.has("error") && jsonResponse.getJSONObject("error").has("message")) {
return new APITatarException(jsonResponse.getJSONObject("error").getString("message"));
} else if(jsonResponse.has("status") && jsonResponse.getString("status").equals("Unauthorized")) {
return new APITatarUnauthorizationException();
} else {
return new APITatarException(response.getResponse());
}
} catch (JSONException exception) {
return new APITatarException(response.getResponse());
}
}