Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 95e1b2d

Browse files
Artemy TregubenkoIgorMinar
Artemy Tregubenko
authored andcommitted
fix($httpBackend): cancelled JSONP requests will not print error in the console
When you cancel a JSONP request, angular deletes the callback for it. However the script still executes, and since the callback is now deleted and undefined, the script throws an exception visible in the console. The quick fix for this is not to delete the callback, but replace it with `angular.noop`. Closes #5615 Closes #5616
1 parent 75345e3 commit 95e1b2d

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/ng/httpBackend.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function createHttpBackend($browser, createXhr, $browserDefer, callbacks, rawDoc
5454
} else {
5555
completeRequest(callback, status || -2);
5656
}
57-
delete callbacks[callbackId];
57+
callbacks[callbackId] = angular.noop;
5858
});
5959
} else {
6060

test/ng/httpBackendSpec.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ describe('$httpBackend', function() {
330330
script.onload();
331331
}
332332

333-
expect(callbacks[callbackId]).toBeUndefined();
333+
expect(callbacks[callbackId]).toBe(angular.noop);
334334
expect(fakeDocument.body.removeChild).toHaveBeenCalledOnceWith(script);
335335
});
336336

@@ -397,7 +397,7 @@ describe('$httpBackend', function() {
397397
});
398398

399399

400-
it('should abort request on timeout', function() {
400+
it('should abort request on timeout and replace callback with noop', function() {
401401
callback.andCallFake(function(status, response) {
402402
expect(status).toBe(-1);
403403
});
@@ -406,9 +406,14 @@ describe('$httpBackend', function() {
406406
expect(fakeDocument.$$scripts.length).toBe(1);
407407
expect(fakeTimeout.delays[0]).toBe(2000);
408408

409+
var script = fakeDocument.$$scripts.shift(),
410+
callbackId = script.src.match(SCRIPT_URL)[2];
411+
409412
fakeTimeout.flush();
410413
expect(fakeDocument.$$scripts.length).toBe(0);
411414
expect(callback).toHaveBeenCalledOnce();
415+
416+
expect(callbacks[callbackId]).toBe(angular.noop);
412417
});
413418

414419

0 commit comments

Comments
 (0)