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

Commit 0c4266d

Browse files
committed
fixup! fix($q): treat thrown errors as regular rejections
1 parent 58cc8a5 commit 0c4266d

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

Diff for: src/ng/compile.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -3052,8 +3052,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
30523052

30533053
$compileNode.empty();
30543054

3055-
$templateRequest(templateUrl).
3056-
then(function(content) {
3055+
$templateRequest(templateUrl)
3056+
.then(function(content) {
30573057
var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn;
30583058

30593059
content = denormalizeTemplate(content);
@@ -3131,13 +3131,11 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
31313131
childBoundTranscludeFn);
31323132
}
31333133
linkQueue = null;
3134-
}).
3135-
catch(function(error) {
3134+
}).catch(function(error) {
31363135
if (error instanceof Error) {
31373136
$exceptionHandler(error);
31383137
}
3139-
}).
3140-
catch(noop);
3138+
}).catch(noop);
31413139

31423140
return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {
31433141
var childBoundTranscludeFn = boundTranscludeFn;

Diff for: test/ng/templateRequestSpec.js

+40-28
Original file line numberDiff line numberDiff line change
@@ -114,47 +114,59 @@ describe('$templateRequest', function() {
114114
expect($templateCache.get('tpl.html')).toBe('matias');
115115
}));
116116

117-
it('should throw an error when the template is not found',
118-
inject(function($exceptionHandler, $httpBackend, $rootScope, $templateRequest) {
119-
$httpBackend.expectGET('tpl.html').respond(404, '', {}, 'Not found');
117+
it('should call `$exceptionHandler` on request error', function() {
118+
module(function($exceptionHandlerProvider) {
119+
$exceptionHandlerProvider.mode('log');
120+
});
120121

121-
$templateRequest('tpl.html').catch(noop);
122+
inject(function($exceptionHandler, $httpBackend, $templateRequest) {
123+
$httpBackend.expectGET('tpl.html').respond(404, '', {}, 'Not Found');
124+
125+
var err;
126+
$templateRequest('tpl.html').catch(function(reason) { err = reason; });
122127
$httpBackend.flush();
123128

129+
expect(err.message).toMatch(new RegExp(
130+
'^\\[\\$compile:tpload] Failed to load template: tpl\\.html ' +
131+
'\\(HTTP status: 404 Not Found\\)'));
124132
expect($exceptionHandler.errors[0].message).toMatch(new RegExp(
125133
'^\\[\\$compile:tpload] Failed to load template: tpl\\.html ' +
126-
'\\(HTTP status: 404 Not found\\)'));
127-
})
128-
);
129-
130-
it('should not throw when the template is not found and ignoreRequestError is true',
131-
inject(function($rootScope, $templateRequest, $httpBackend) {
132-
133-
$httpBackend.expectGET('tpl.html').respond(404);
134-
135-
var err;
136-
$templateRequest('tpl.html', true).catch(function(reason) { err = reason; });
137-
138-
$rootScope.$digest();
139-
$httpBackend.flush();
134+
'\\(HTTP status: 404 Not Found\\)'));
135+
});
136+
});
140137

141-
expect(err.status).toBe(404);
142-
}));
138+
it('should not call `$exceptionHandler` on request error when `ignoreRequestError` is true',
139+
function() {
140+
module(function($exceptionHandlerProvider) {
141+
$exceptionHandlerProvider.mode('log');
142+
});
143143

144-
it('should not throw an error when the template is empty',
145-
inject(function($rootScope, $templateRequest, $httpBackend) {
144+
inject(function($exceptionHandler, $httpBackend, $templateRequest) {
145+
$httpBackend.expectGET('tpl.html').respond(404);
146146

147-
$httpBackend.expectGET('tpl.html').respond('');
147+
var err;
148+
$templateRequest('tpl.html', true).catch(function(reason) { err = reason; });
149+
$httpBackend.flush();
148150

149-
$templateRequest('tpl.html');
151+
expect(err.status).toBe(404);
152+
expect($exceptionHandler.errors).toEqual([]);
153+
});
154+
}
155+
);
150156

151-
$rootScope.$digest();
157+
it('should not call `$exceptionHandler` when the template is empty',
158+
inject(function($exceptionHandler, $httpBackend, $rootScope, $templateRequest) {
159+
$httpBackend.expectGET('tpl.html').respond('');
152160

153-
expect(function() {
161+
var onError = jasmine.createSpy('onError');
162+
$templateRequest('tpl.html').catch(onError);
154163
$rootScope.$digest();
155164
$httpBackend.flush();
156-
}).not.toThrow();
157-
}));
165+
166+
expect(onError).not.toHaveBeenCalled();
167+
expect($exceptionHandler.errors).toEqual([]);
168+
})
169+
);
158170

159171
it('should accept empty templates and refuse null or undefined templates in cache',
160172
inject(function($rootScope, $templateRequest, $templateCache, $sce) {

0 commit comments

Comments
 (0)