jameslnewell / xhr-mock

Utility for mocking XMLHttpRequest.
196 stars 48 forks source link

Handle different errors #41

Closed jameslnewell closed 6 years ago

jameslnewell commented 6 years ago

From #32:

Currently only one type of error handling is implemented (and it doesn't call loadend) and we don't have a way to tell xhr-mock which type of error handling to execute. We need to implement a way for developers to indicate which error handling we should use.

Something like this could work???

import mock, {RequestError, ResponseError, EndOfBodyError} from 'xhr-mock';

mock.get('/', () => Promise.reject(new ResponseError()));
jameslnewell commented 6 years ago

Upon reading the spec I realised that all errors still result in loadend being dispatched and therefore there's very little to gain by having separate error handling.

I've updated the behaviour to follow the spec more closely and dispatch the loadend event.

https://github.com/jameslnewell/xhr-mock/commit/78d5094b2193f6afddf9a4ad899579bb3c4a3d52

xhr-mock@2.0.0-preview.15