You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an error occurr, the exception can be obtained using
final RequestException exception = (RequestException) getArgument(4);
But the exception is not the original error, because the text "HTTP ERROR: 500 Internal Server Error" is prepended. Therefore, if the original error is {message:"my message"}, the RequestException.getMessage() will return
HTTP ERROR: 500 Internal Server Error {message:"my message"}.
Then I cannot convert easily to a json object to get the error.
Another improvement is to provide access to the original response from the server, which would give more options even to circumvent problems. For example, in this particular case, the problem could be overcome using response.getText () instead of exception.getMessage().
The code bellow:
public void onResponseReceived(Request request, Response response) {
int status = response.getStatusCode();
if (status <= 0 || status >= 400) {
String statusText = status <= 0 ? "Bad CORS" : response.getStatusText();
onError(request, new RequestException("HTTP ERROR: " + status + " " + statusText + "\n"
+ response.getText()));
} else {
dfd.resolve(response, request);
}
}
Could be change to (note the response object as second param of onError call):
public void onResponseReceived(Request request, Response response) {
int status = response.getStatusCode();
if (status <= 0 || status >= 400) {
String statusText = status <= 0 ? "Bad CORS" : response.getStatusText();
onError(request, response, new RequestException("HTTP ERROR: " + status + " " + statusText + "\n"
+ response.getText()));
} else {
dfd.resolve(response, request);
}
}
Thanks,
Fabio.
The text was updated successfully, but these errors were encountered:
When an error occurr, the exception can be obtained using
But the exception is not the original error, because the text "HTTP ERROR: 500 Internal Server Error" is prepended. Therefore, if the original error is {message:"my message"}, the RequestException.getMessage() will return
Then I cannot convert easily to a json object to get the error.
Another improvement is to provide access to the original response from the server, which would give more options even to circumvent problems. For example, in this particular case, the problem could be overcome using response.getText () instead of exception.getMessage().
The code bellow:
Could be change to (note the response object as second param of onError call):
Thanks,
Fabio.
The text was updated successfully, but these errors were encountered: