angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

ngRoute: handle error when template loading fails

Open provegard opened this issue 12 years ago • 6 comments

If I have a templateUrl in my route definition, and the URL is wrong, no particular error/exception handler is called. The code in ngRoute is:

  template = $http.get(templateUrl, {cache: $templateCache}).
        then(function(response) { return response.data; });

It would be convenient to be able to deal with an error at this point.

provegard avatar Mar 07 '14 16:03 provegard

Or is the proper solution to use an HTTP interceptor and deal with the error there?

provegard avatar Mar 07 '14 16:03 provegard

@provegard yes, we could log it or throw a minErr. What would you expect to happen when a template can't be fetched?

pkozlowski-opensource avatar Mar 08 '14 18:03 pkozlowski-opensource

@pkozlowski-opensource I would expect there to be a facility similar to $exceptionHandler that would let me handle errors like this.

provegard avatar Mar 09 '14 00:03 provegard

+1

ChuckJHardy avatar Aug 06 '14 09:08 ChuckJHardy

Would be great +1

lminaudier avatar Aug 06 '14 09:08 lminaudier

This throws the tpload error since 1.3, which can be accessed as the 4 parameter of $routeChangeError. It's catchable by an interceptor, too.

Narretz avatar Oct 10 '17 12:10 Narretz