feat(http): xhr error listener invokes throw on EventEmitter
Closes #2667
This commit is contained in:
parent
3b9411cbeb
commit
f2d3bdb801
|
@ -1,5 +1,5 @@
|
|||
import {ConnectionBackend, Connection} from '../interfaces';
|
||||
import {ReadyStates, RequestMethods, RequestMethodsMap} from '../enums';
|
||||
import {ReadyStates, RequestMethods, RequestMethodsMap, ResponseTypes} from '../enums';
|
||||
import {Request} from '../static_request';
|
||||
import {Response} from '../static_response';
|
||||
import {ResponseOptions, BaseResponseOptions} from '../base_response_options';
|
||||
|
@ -59,6 +59,14 @@ export class XHRConnection implements Connection {
|
|||
// TODO(gdi2290): defer complete if array buffer until done
|
||||
ObservableWrapper.callReturn(this.response);
|
||||
});
|
||||
|
||||
this._xhr.addEventListener('error', (err) => {
|
||||
var responseOptions = new ResponseOptions({body: err, type: ResponseTypes.Error});
|
||||
if (isPresent(baseResponseOptions)) {
|
||||
responseOptions = baseResponseOptions.merge(responseOptions);
|
||||
}
|
||||
ObservableWrapper.callThrow(this.response, new Response(responseOptions))
|
||||
});
|
||||
// TODO(jeffbcross): make this more dynamic based on body type
|
||||
|
||||
if (isPresent(req.headers)) {
|
||||
|
|
|
@ -118,6 +118,15 @@ export function main() {
|
|||
expect(abortSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create an error Response on error', inject([AsyncTestCompleter], async => {
|
||||
var connection = new XHRConnection(sampleRequest, new MockBrowserXHR(),
|
||||
new ResponseOptions({type: ResponseTypes.Error}));
|
||||
ObservableWrapper.subscribe(connection.response, null, res => {
|
||||
expect(res.type).toBe(ResponseTypes.Error);
|
||||
async.done();
|
||||
});
|
||||
existingXHRs[0].dispatchEvent('error');
|
||||
}));
|
||||
|
||||
it('should automatically call open with method and url', () => {
|
||||
new XHRConnection(sampleRequest, new MockBrowserXHR());
|
||||
|
|
Loading…
Reference in New Issue