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

Include statusText in error object #511

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ErikLarsson82
Copy link
Contributor

When using timeout option for XHR, the error objects needs to differentiate between timeouts and other errors if the applications should be able to handle these differently.

@saponifi3d
Copy link
Contributor

Thanks for the contrib!

I was wondering what you're statusText will be set to when you're using the timeout option? From the docs I was reading it seems like it's simply a bit extra text output from the status code itself, so it seems like you should be able to get all the information from that?

Thanks in advance for furthering my knowledge about XHR statusText too! Would the readyState be helpful for you in this case too? https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState

@ErikLarsson82
Copy link
Contributor Author

The error code is 0 when reaching timeout. This is probably incorrect and should probably be solved in a different pull request. I have not been able to figure out why the error code is 0. But i did try to propagate the statusText and our code works using this modification. The statusText simply is 'timeout' in this situation.

@saponifi3d
Copy link
Contributor

Do you think we will need to add any other attributes to this error? There are a lot of additional properties we are not sending in the error from the response.

It also seems like a candidate to make a new Error type so we can catch only these errors in a try / catch block. Thoughts? (I can update that in a separate PR)

@@ -187,6 +187,7 @@ Fetcher.prototype.fetchFromApi = function(spec, options, callback) {
respOutput = JSON.stringify(resp);
err = new Error("ERROR fetching model '" + fetcher.modelUtils.modelName(model.constructor) + "' with options '" + JSON.stringify(options) + "'. Response: " + respOutput);
err.status = resp.status;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say to use underscore and a whitelist instead, this way we can easily add or remove things from the whitelist.

_.extend(err, _.pick(resp, [
  'status', 'statusText'
]));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants