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

$templateCache / $compile loses error context when HTTP request for template fails #10514

Closed
niallsmart opened this issue Dec 18, 2014 · 7 comments

Comments

@niallsmart
Copy link
Contributor

The $templateCache service throws an exception if the HTTP request to fetch the template fails, however the exception message contains no useful context other than the fact that the request failed.

The exception should include the error code and other context.

https://github.com/angular/angular.js/blob/g3_v1_3/src/ng/templateRequest.js#L52

@niallsmart niallsmart changed the title $templateCache / $compile loses error context when loading template fails $templateCache / $compile loses error context when HTTP request for template fails Dec 18, 2014
@pkozlowski-opensource
Copy link
Member

@niallsmart what would you, ideally, like to see as the additional context? I can think of HTTP response status code / text. But you can get those from the network of a browser's dev tool.

The trouble I can see here is that a promise can be either rejected with a failed HTTP response (I guess this would be a standard case) or with any other object ($http interceptors can do whatever they want...). So it will be a bit tricky to get perfectly meaningful details in all the cases...

@niallsmart
Copy link
Contributor Author

@pkozlowski-opensource yeah, the console is definitely the best way to debug this exception on developer machines. however, the context is that we're seeing this exception intermittently on end-user browsers – it's reported to us via our exception tracking system, but hard to debug without more context on why the requests are failing.

Re implementation, while interceptors could reject with any random object, couldn't that be considered breaking the $http API?

@pkozlowski-opensource
Copy link
Member

@niallsmart so, at the end of the day we've got only 2 pieces of info that might help tracking down issues: http response status code / text. I wonder if this would be enough to track down the problems you end-users are seeing...

@niallsmart
Copy link
Contributor Author

@pkozlowski-opensource well, the status code would definitely be useful context but I agree, there's probably not enough to track down the root cause. in this particular case there seems to be an unreliable proxy somewhere in the chain which is dropping the connection and Chrome reports the code as "0". What are your thoughts on including "" + code in the error message? That seems safe even when an interceptor has rejected the promise with something that breaks the $http API

@niallsmart
Copy link
Contributor Author

Actually in Angular 1.3's $templateRequest, that's going to look more like this:

   throw $compileMinErr('tpload', 'Failed to load template: {0} (response: {1})', tpl, "" + resp);

Alternatively you could just pass in the resp object and let minErr / toDebugString dump the longer format.

@pkozlowski-opensource
Copy link
Member

@niallsmart I'm not sure dumping the whole response makes much sense as it can be rather large object (for example it has entire config inside). Looking at all the fields of $http response I think that the only reasonable, additional info is response status / statusText.

@niallsmart
Copy link
Contributor Author

@pkozlowski-opensource ah yes, totally agree. Logging status and statusText seems reasonable.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.