This repository has been archived by the owner on Aug 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#501 Handle 404 errors at Express backend at at Angular frontend
- `/{api|modules|lib}/*` returns error page when path doesn’t exist (from Express). - `/*` always returns index (from Express), but if `$state` doesn’t exist, Angular redirects to `/not-found` (no 404 status in that case though!) - If `Accept: application/json` header is present without `Accept: text/html`, return error as json. Hence looking at non existing /api/* paths with browser would show html error, but querying them with script would return json. - Slightly prettier 404 error Test: ```bash curl http://localhost:3000/api/notfound -4 -H "Accept: application/json" ``` => json error. ```bash curl http://localhost:3000/api/notfound -4 -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0 .8" ``` => html error (imitates Chrome’s Accept header). Starting point was @dotch’s PL: #503 And `req.accepts()` idea came from http://stackoverflow.com/a/9802006
- Loading branch information
Showing
4 changed files
with
41 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Page Not Found</h1> | ||
<div class="alert alert-danger" role="alert"> | ||
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> | ||
<span class="sr-only">Error:</span> | ||
Page Not Found | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters