I am looking into handling 404 requests from api call where I am returning html when it occours.
$http.get('/api/house/' + $routeParams.id)
.then(function (res) {
$scope.houses = res.data;
}, function (err) {
//when not found I am binding html from response
if(err.status == 404){
$scope.errHtml = $sce.trustAsHtml(err.data);
}
});
returned html for 404:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="/resources/css/bootstrap.min.css">
<title>404</title>
</head>
<body>
<div>test 404</div>
</body>
</html>
in view I have:
<div ng-bind-html="errHtml"></div>
I am trying to understand if this is the best way to handle 404 from api call in angular js