diff --git a/modules/angular2/src/render/dom/compiler/compiler.ts b/modules/angular2/src/render/dom/compiler/compiler.ts index 2d4ab3b7c4..9f1c224c65 100644 --- a/modules/angular2/src/render/dom/compiler/compiler.ts +++ b/modules/angular2/src/render/dom/compiler/compiler.ts @@ -36,8 +36,9 @@ export class DomCompiler extends RenderCompiler { var tplPromise = this._templateLoader.load(template); return PromiseWrapper.then( tplPromise, (el) => this._compileTemplate(template, el, ProtoViewDto.COMPONENT_VIEW_TYPE), - (_) => { - throw new BaseException(`Failed to load the template "${template.componentId}"`); + (e) => { + throw new BaseException( + `Failed to load the template for "${template.componentId}" : ${e}`); }); } diff --git a/modules/angular2/src/render/dom/compiler/template_loader.ts b/modules/angular2/src/render/dom/compiler/template_loader.ts index 51e891bbd9..4ebfe2cd7e 100644 --- a/modules/angular2/src/render/dom/compiler/template_loader.ts +++ b/modules/angular2/src/render/dom/compiler/template_loader.ts @@ -32,10 +32,14 @@ export class TemplateLoader { var promise = StringMapWrapper.get(this._htmlCache, url); if (isBlank(promise)) { - promise = this._xhr.get(url).then(function(html) { + // TODO(vicb): change error when TS gets fixed + // https://github.com/angular/angular/issues/2280 + // throw new BaseException(`Failed to fetch url "${url}"`); + promise = PromiseWrapper.then(this._xhr.get(url), html => { var template = DOM.createTemplate(html); return template; - }); + }, _ => PromiseWrapper.reject(new BaseException(`Failed to fetch url "${url}"`), null)); + StringMapWrapper.set(this._htmlCache, url, promise); } diff --git a/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts b/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts index eeca0a8966..ec9107808b 100644 --- a/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts +++ b/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts @@ -103,7 +103,8 @@ export function runCompilerCommonTests() { PromiseWrapper.catchError( compiler.compile(new ViewDefinition({componentId: 'someId', absUrl: 'someUrl'})), (e) => { - expect(e.message).toContain(`Failed to load the template "someId"`); + expect(e.message).toEqual( + 'Failed to load the template for "someId" : Failed to fetch url "someUrl"'); async.done(); return null; }); @@ -208,9 +209,9 @@ class FakeTemplateLoader extends TemplateLoader { if (isPresent(template.absUrl)) { var content = MapWrapper.get(this._urlData, template.absUrl); - if (isPresent(content)) { - return PromiseWrapper.resolve(DOM.createTemplate(content)); - } + return isPresent(content) ? + PromiseWrapper.resolve(DOM.createTemplate(content)) : + PromiseWrapper.reject(`Failed to fetch url "${template.absUrl}"`, null); } return PromiseWrapper.reject('Load failed', null); diff --git a/modules/angular2/test/render/dom/compiler/template_loader_spec.ts b/modules/angular2/test/render/dom/compiler/template_loader_spec.ts index 343570f0a4..7603ff3cbe 100644 --- a/modules/angular2/test/render/dom/compiler/template_loader_spec.ts +++ b/modules/angular2/test/render/dom/compiler/template_loader_spec.ts @@ -78,7 +78,7 @@ export function main() { var template = new ViewDefinition({absUrl: 'base/foo'}); PromiseWrapper.then(loader.load(template), function(_) { throw 'Unexpected response'; }, function(error) { - expect(error).toEqual('Failed to load base/foo'); + expect(error.message).toEqual('Failed to fetch url "base/foo"'); async.done(); }); xhr.flush();