Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promise.fail(..) should return the original error #359

Open
lisboa opened this issue Sep 1, 2015 · 0 comments
Open

Promise.fail(..) should return the original error #359

lisboa opened this issue Sep 1, 2015 · 0 comments
Labels

Comments

@lisboa
Copy link

lisboa commented Sep 1, 2015

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.

@olafleur olafleur added the bug label Sep 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants