-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy patherrors.js
More file actions
45 lines (41 loc) · 1.04 KB
/
errors.js
File metadata and controls
45 lines (41 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
{
const service = 'api';
const errors = {
log, errorView
};
module.exports = errors;
function log(error, req, res, next) {
console.log("\n");
console.log(error);
res.status(error.code || error.statusCode).end(JSON.stringify({error}));
}
function safe( data ) {
const dataString = JSON.stringify(data);
const safe = dataString.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
return JSON.parse(safe);
}
function errorView( data ) {
data = safe(data);
return `
<article class=modal>
<h1>An error occurred</h1>
<section class=info>
<p class=long>
${data.message}
</section>
<section class=control>
<button id=go_back name=action value=go_back>Go back</button>
</section>
<script>
"use strict";
{
document.querySelector('#go_back').onclick = () => {
window.history.back();
};
}
</script>
</article>
`;
}
}