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

Commit a47ea79

Browse files
committed
test($http): ensure json deserialization errors are forwarded to error handler
Since e13eeab, errors thrown from onFulfilled and onRejected handlers are passed to the regular http error handlers. Before this, JSON deserialization errors lead to hard application errors, and could not be handled by application code. This behavior was introduced in 7b6c1d0, and originally, a malformed JSON string was forwarded as the data to the http success response handler. This commit adds a specifc test case, even though the behavior is unlikely to break in the future without a change in the $q rejection handling. Related #11433 Closes #15689
1 parent 5ca0de6 commit a47ea79

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

test/ng/httpSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1368,6 +1368,20 @@ describe('$http', function() {
13681368
expect(callback.calls.argsFor(1)[0].data).toEqual('{"is": "not"} ["json"]');
13691369
}
13701370
);
1371+
1372+
it('should forward json deserialization errors to the http error handler',
1373+
function() {
1374+
var errCallback = jasmine.createSpy('error');
1375+
1376+
$httpBackend.expect('GET', '/url').respond('abcd', {'Content-Type': 'application/json'});
1377+
$http({method: 'GET', url: '/url'}).then(callback).catch(errCallback);
1378+
$httpBackend.flush();
1379+
1380+
expect(callback).not.toHaveBeenCalled();
1381+
expect(errCallback).toHaveBeenCalledOnce();
1382+
expect(errCallback.calls.mostRecent().args[0]).toEqual(jasmine.any(SyntaxError));
1383+
});
1384+
13711385
});
13721386

13731387

0 commit comments

Comments
 (0)