Skip to content

Commit 019dcc8

Browse files
committed
added expressjs error handler/native npm package
1 parent 8665d86 commit 019dcc8

24 files changed

Lines changed: 490 additions & 24 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.buildpath
55
.git
66
gfx/*
7+
node_modules*
78
PublicHtml/*

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,40 @@ location /ErrorPages/ {
6060
}
6161
```
6262

63+
## expressjs Integration ##
64+
65+
HttpErrorPages are available as NPM-Package - just install `http-error-pages` via **npm/yarn**
66+
67+
```terminal
68+
npm install http-error-pages --save
69+
```
70+
71+
Example
72+
73+
```js
74+
var _express = require('express');
75+
var _webapp = _express();
76+
var _httpErrorPages = require('http-error-pages');
77+
78+
// demo handler
79+
_webapp.get('/', function(req, res){
80+
res.type('.txt').send('HttpErrorPages Demo');
81+
});
82+
83+
// throw an 403 error
84+
_webapp.get('/my403error', function(req, res, next){
85+
var myError = new Error();
86+
myError.status = 403;
87+
next(myError);
88+
});
89+
90+
// use http error pages handler (final statement!)
91+
_httpErrorPages(_webapp);
92+
93+
// start service
94+
_webapp.listen(8888);
95+
```
96+
6397
## Apache Httpd Integration ##
6498
[Apache Httpd 2.x](http://httpd.apache.org/) supports custom error-pages using multiple [ErrorDocument](http://httpd.apache.org/docs/2.4/mod/core.html#errordocument) directives.
6599

dist/HTTP0.html

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<!-- Simple HttpErrorPages | MIT X11 License | https://github.com/AndiDittrich/HttpErrorPages -->
5+
6+
<meta charset="utf-8" />
7+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
8+
<meta name="viewport" content="width=device-width, initial-scale=1" />
9+
10+
<title>We've got some trouble | {{code}} - {{title}}</title>
11+
12+
<style type="text/css">/*! normalize.css v5.0.0 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;line-height:1.15;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,footer,header,nav,section{display:block}h1{font-size:2em;margin:.67em 0}figcaption,figure,main{display:block}figure{margin:1em 40px}hr{box-sizing:content-box;height:0;overflow:visible}pre{font-family:monospace,monospace;font-size:1em}a{background-color:transparent;-webkit-text-decoration-skip:objects}a:active,a:hover{outline-width:0}abbr[title]{border-bottom:none;text-decoration:underline;text-decoration:underline dotted}b,strong{font-weight:inherit}b,strong{font-weight:bolder}code,kbd,samp{font-family:monospace,monospace;font-size:1em}dfn{font-style:italic}mark{background-color:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}audio,video{display:inline-block}audio:not([controls]){display:none;height:0}img{border-style:none}svg:not(:root){overflow:hidden}button,input,optgroup,select,textarea{font-family:sans-serif;font-size:100%;line-height:1.15;margin:0}button,input{overflow:visible}button,select{text-transform:none}[type=reset],[type=submit],button,html [type=button]{-webkit-appearance:button}[type=button]::-moz-focus-inner,[type=reset]::-moz-focus-inner,[type=submit]::-moz-focus-inner,button::-moz-focus-inner{border-style:none;padding:0}[type=button]:-moz-focusring,[type=reset]:-moz-focusring,[type=submit]:-moz-focusring,button:-moz-focusring{outline:1px dotted ButtonText}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress{display:inline-block;vertical-align:baseline}textarea{overflow:auto}[type=checkbox],[type=radio]{box-sizing:border-box;padding:0}[type=number]::-webkit-inner-spin-button,[type=number]::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}[type=search]::-webkit-search-cancel-button,[type=search]::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details,menu{display:block}summary{display:list-item}canvas{display:inline-block}template{display:none}[hidden]{display:none}/*! Simple HttpErrorPages | MIT X11 License | https://github.com/AndiDittrich/HttpErrorPages */body,html{width:100%;height:100%;background-color:#21232a}body{color:#fff;text-align:center;text-shadow:0 2px 4px rgba(0,0,0,.5);padding:0;min-height:100%;-webkit-box-shadow:inset 0 0 75pt rgba(0,0,0,.8);box-shadow:inset 0 0 75pt rgba(0,0,0,.8);display:table;font-family:"Open Sans",Arial,sans-serif}h1{font-family:inherit;font-weight:500;line-height:1.1;color:inherit;font-size:36px}h1 small{font-size:68%;font-weight:400;line-height:1;color:#777}a{text-decoration:none;color:#fff;font-size:inherit;border-bottom:dotted 1px #707070}.lead{color:silver;font-size:21px;line-height:1.4}.cover{display:table-cell;vertical-align:middle;padding:0 20px}footer{position:fixed;width:100%;height:40px;left:0;bottom:0;color:#a0a0a0;font-size:14px}</style>
13+
</head>
14+
15+
<body>
16+
<div class="cover">
17+
<h1>{{title}} <small>Error {{code}}</small></h1>
18+
<p class="lead">{{message}}</p>
19+
</div>
20+
21+
</body>
22+
</html>

dist/HTTP400.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ <h1>Bad Request <small>Error 400</small></h1>
1818
<p class="lead">The server cannot process the request due to something that is perceived to be a client error.</p>
1919
</div>
2020

21-
22-
</body>
21+
</body>
2322
</html>

dist/HTTP401.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ <h1>Unauthorized <small>Error 401</small></h1>
1818
<p class="lead">The requested resource requires an authentication.</p>
1919
</div>
2020

21-
22-
</body>
21+
</body>
2322
</html>

dist/HTTP403.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ <h1>Access Denied <small>Error 403</small></h1>
1818
<p class="lead">The requested resource requires an authentication.</p>
1919
</div>
2020

21-
22-
</body>
21+
</body>
2322
</html>

dist/HTTP404.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ <h1>Resource not found <small>Error 404</small></h1>
1818
<p class="lead">The requested resource could not be found but may be available again in the future.</p>
1919
</div>
2020

21-
22-
</body>
21+
</body>
2322
</html>

dist/HTTP500.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ <h1>Webservice currently unavailable <small>Error 500</small></h1>
1919
Our service team has been dispatched to bring it back online.</p>
2020
</div>
2121

22-
23-
</body>
22+
</body>
2423
</html>

dist/HTTP501.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ <h1>Not Implemented <small>Error 501</small></h1>
1818
<p class="lead">The Webserver cannot recognize the request method.</p>
1919
</div>
2020

21-
22-
</body>
21+
</body>
2322
</html>

dist/HTTP502.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ <h1>Webservice currently unavailable <small>Error 502</small></h1>
1919
Our service team has been dispatched to bring it back online.</p>
2020
</div>
2121

22-
23-
</body>
22+
</body>
2423
</html>

0 commit comments

Comments
 (0)