Imagine having routes set up in the configuration:
$routeProvider
.when('/person/:person_id', {
controller: 'person',
templateUrl: 'partials/person.html',
resolve: {
data: ['api', '$route',
function(api, $route) {
return api('api/person/page/' + $route.current.params.person_id);
}
]
}
})
.otherwise({
controller: 'error',
templateUrl: 'partials/404.html',
});
In addition, we are confident that all controllers, views and API endpoints are in place.
Now, if we venture to a non-existing route like: blahblah/foobar
, the router functions as expected by executing the 'error' controller and displaying the 404.html content.
Yet, when the resolution for /person/:person_id
fails due to a 404 response from the API endpoint (indicating the person does not exist), Angular displays slightly unpredictable behavior - it skips running both the 'person' controller and the 'error' controller but still shows the 404 content correctly.
I am seeking a solution on how to make Angular trigger the 'error' controller upon resolution failure, similar to what happens with non-existing paths.
-EDIT-
Please note that, based on application constraints, using redirection is not an option.
The router must remain on the incorrect URL rather than redirecting to a specific 404 route.