-
-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Labels
Description
I'm submitting a bug report
- Library Version:
1.0.4
Please tell us about your environment:
-
Operating System:
OSX 10.x -
Browser:
Chrome 56 | Firefox 51 -
Language:
es2015
Current behavior:
An interceptor can delay XHR sending, and if the app cancels the request before it was send then the promise never resolved. HttpClient.pendingRequests collection grows with each request. Sample code:
initTest() {
console.log('Test')
this.testClient = new HttpClient();
this.testClient.configure(config => {
config.withInterceptor({
request(message) {
//Delay request for 1 second
return new Promise((resolve, reject) => {
setTimeout(() => {resolve(message)}, 1000)
})
},
});
});
}
test() {
console.log('Test')
let promise = this.testClient.get('/test'); //preserve original promise with abort method
promise.then(response => {
console.log('response', response)
})
.catch(e => {
console.log('error', e)
})
promise.abort()
console.log('Pending requests', this.testClient.pendingRequests)
}
https://github.com/aurelia/http-client/blob/master/src/request-message-processor.js line 152 is invoked during processing phase.
if (this.isAborted) {
// Some interceptors can delay sending of XHR, so when abort is called
// before XHR is actually sent we abort() instead send()
this.xhr.abort();
} else {
Line 140 - xhr.onabort = (e) => { never invoked
Expected/desired behavior:
Expected result - promise either resolved or rejected