fix($emplateRequest): propagate rejection reason when ignoreRequestError flag is set

Closes #10266
This commit is contained in:
Pawel Kozlowski
2014-11-29 12:29:54 +01:00
parent ab2531143e
commit f6458826ac
2 changed files with 16 additions and 2 deletions

View File

@@ -48,12 +48,12 @@ function $TemplateRequestProvider() {
return html;
}, handleError);
function handleError() {
function handleError(resp) {
self.totalPendingRequests--;
if (!ignoreRequestError) {
throw $compileMinErr('tpload', 'Failed to load template: {0}', tpl);
}
return $q.reject();
return $q.reject(resp);
}
}

View File

@@ -43,6 +43,20 @@ describe('$templateRequest', function() {
}).toThrowMinErr('$compile', 'tpload', 'Failed to load template: tpl.html');
}));
it('should not throw when the template is not found and ignoreRequestError is true',
inject(function($rootScope, $templateRequest, $httpBackend) {
$httpBackend.expectGET('tpl.html').respond(404);
var err;
$templateRequest('tpl.html', true).catch(function(reason) { err = reason; });
$rootScope.$digest();
$httpBackend.flush();
expect(err.status).toBe(404);
}));
it('should not throw an error when the template is empty',
inject(function($rootScope, $templateRequest, $httpBackend) {