Include statusText in error object#511
Conversation
|
Thanks for the contrib! I was wondering what you're 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 |
|
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. |
|
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; | |||
There was a problem hiding this comment.
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'
]));
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.