strong-error-handler 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/ISSUE_TEMPLATE.md +22 -21
- package/.github/PULL_REQUEST_TEMPLATE.md +5 -4
- package/CHANGES.md +38 -0
- package/CODEOWNERS +5 -0
- package/LICENSE.md +1 -1
- package/README.md +9 -1
- package/lib/content-negotiation.js +1 -1
- package/lib/data-builder.js +18 -24
- package/package.json +12 -12
- package/views/default-error.ejs +4 -4
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
<!--
|
|
2
|
-
|
|
2
|
+
Questions:
|
|
3
|
+
https://groups.google.com/forum/#!forum/loopbackjs
|
|
3
4
|
https://gitter.im/strongloop/loopback
|
|
4
|
-
|
|
5
|
-
- Immediate support is available through our subscription plans, see
|
|
5
|
+
Immediate support:
|
|
6
6
|
https://strongloop.com/api-connect-faqs/
|
|
7
|
+
https://strongloop.com/node-js/subscription-plans/
|
|
7
8
|
-->
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
# Description/Steps to reproduce
|
|
10
11
|
|
|
11
12
|
<!--
|
|
12
|
-
|
|
13
|
+
If feature: A description of the feature
|
|
14
|
+
If bug: Steps to reproduce
|
|
13
15
|
-->
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
- [ ] Feature request
|
|
17
|
-
|
|
18
|
-
### Description of feature (or steps to reproduce if bug)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
### Link to sample repo to reproduce issue (if bug)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### Expected result
|
|
17
|
+
# Link to reproduction sandbox
|
|
27
18
|
|
|
19
|
+
<!--
|
|
20
|
+
Link to an app sandbox for reproduction
|
|
28
21
|
|
|
22
|
+
Note: Failure to provide a sandbox application for reproduction purposes will result in the issue being closed.
|
|
23
|
+
-->
|
|
29
24
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
# Expected result
|
|
33
26
|
|
|
34
|
-
|
|
27
|
+
<!--
|
|
28
|
+
Also include actual results if bug
|
|
29
|
+
-->
|
|
35
30
|
|
|
31
|
+
# Additional information
|
|
36
32
|
|
|
33
|
+
<!--
|
|
34
|
+
Copy+paste the output of these two commands:
|
|
35
|
+
node -e 'console.log(process.platform, process.arch, process.versions.node)'
|
|
36
|
+
npm ls --prod --depth 0 | grep loopback
|
|
37
|
+
-->
|
|
@@ -6,17 +6,18 @@
|
|
|
6
6
|
<!--
|
|
7
7
|
Please use the following link syntaxes:
|
|
8
8
|
|
|
9
|
-
- #49 (to reference issues in the current repository)
|
|
10
|
-
- strongloop/loopback#49 (to reference issues in another repository)
|
|
9
|
+
- connect to #49 (to reference issues in the current repository)
|
|
10
|
+
- connect to strongloop/loopback#49 (to reference issues in another repository)
|
|
11
11
|
-->
|
|
12
12
|
|
|
13
|
-
-
|
|
13
|
+
- connect to <link_to_referenced_issue>
|
|
14
14
|
|
|
15
15
|
### Checklist
|
|
16
16
|
|
|
17
17
|
<!--
|
|
18
|
-
Please mark your choice with an "x" (i.e. [x], see
|
|
18
|
+
- Please mark your choice with an "x" (i.e. [x], see
|
|
19
19
|
https://github.com/blog/1375-task-lists-in-gfm-issues-pulls-comments)
|
|
20
|
+
- PR's without test coverage will be closed.
|
|
20
21
|
-->
|
|
21
22
|
|
|
22
23
|
- [ ] New tests added or existing tests modified to cover all changes
|
package/CHANGES.md
CHANGED
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
2018-06-12, Version 3.0.0
|
|
2
|
+
=========================
|
|
3
|
+
|
|
4
|
+
* Allow safeFields to work with arrays (shimks)
|
|
5
|
+
|
|
6
|
+
* run lint (shimks)
|
|
7
|
+
|
|
8
|
+
* drop node 4 from travis and update dependencies (shimks)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
2018-03-05, Version 2.3.2
|
|
12
|
+
=========================
|
|
13
|
+
|
|
14
|
+
* Undefined safeFields revert to data #71 (Zak Barbuto)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
2018-01-25, Version 2.3.1
|
|
18
|
+
=========================
|
|
19
|
+
|
|
20
|
+
* Escape strings in HTML output (XSS fix) (Zachery Metcalf)
|
|
21
|
+
|
|
22
|
+
* Update LICENSE.md (Diana Lau)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
2017-10-13, Version 2.3.0
|
|
26
|
+
=========================
|
|
27
|
+
|
|
28
|
+
* update strong-globalize to 3.1.0 (shimks)
|
|
29
|
+
|
|
30
|
+
* CODEOWNERS: add zbarbuto (Miroslav Bajtoš)
|
|
31
|
+
|
|
32
|
+
* Update Issue and PR Templates (#59) (Sakib Hasan)
|
|
33
|
+
|
|
34
|
+
* fixed json typo of server/middleware.json (karanssj4)
|
|
35
|
+
|
|
36
|
+
* Add CODEOWNER file (Diana Lau)
|
|
37
|
+
|
|
38
|
+
|
|
1
39
|
2017-07-20, Version 2.2.0
|
|
2
40
|
=========================
|
|
3
41
|
|
package/CODEOWNERS
ADDED
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -12,6 +12,14 @@ In production mode, `strong-error-handler` omits details from error responses to
|
|
|
12
12
|
|
|
13
13
|
In debug mode, `strong-error-handler` returns full error stack traces and internal details of any error objects to the client in the HTTP responses.
|
|
14
14
|
|
|
15
|
+
## Supported versions
|
|
16
|
+
|
|
17
|
+
Current|Long Term Support|Maintenance
|
|
18
|
+
:-:|:-:|:-:
|
|
19
|
+
3.x|2.x|1.x
|
|
20
|
+
|
|
21
|
+
Learn more about our LTS plan in [docs](http://loopback.io/doc/en/contrib/Long-term-support.html).
|
|
22
|
+
|
|
15
23
|
## Installation
|
|
16
24
|
|
|
17
25
|
```bash
|
|
@@ -121,7 +129,7 @@ Then in `server/middleware.json`, specify your custom error logging function as
|
|
|
121
129
|
"./middleware/error-logger": {},
|
|
122
130
|
"strong-error-handler": {
|
|
123
131
|
"params": {
|
|
124
|
-
log: false
|
|
132
|
+
"log": false
|
|
125
133
|
}
|
|
126
134
|
}
|
|
127
135
|
}
|
package/lib/data-builder.js
CHANGED
|
@@ -8,16 +8,18 @@
|
|
|
8
8
|
var cloneAllProperties = require('../lib/clone.js');
|
|
9
9
|
var httpStatus = require('http-status');
|
|
10
10
|
|
|
11
|
-
module.exports =
|
|
11
|
+
module.exports = buildResponseData;
|
|
12
|
+
|
|
13
|
+
function buildResponseData(err, options) {
|
|
12
14
|
// Debugging mode is disabled by default. When turned on (in dev),
|
|
13
15
|
// all error properties (including) stack traces are sent in the response
|
|
14
|
-
|
|
16
|
+
const isDebugMode = options.debug;
|
|
15
17
|
|
|
16
|
-
if (Array.isArray(err)
|
|
17
|
-
|
|
18
|
+
if (Array.isArray(err)) {
|
|
19
|
+
return serializeArrayOfErrors(err, options);
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
const data = Object.create(null);
|
|
21
23
|
fillStatusCode(data, err);
|
|
22
24
|
|
|
23
25
|
if (typeof err !== 'object') {
|
|
@@ -29,35 +31,25 @@ module.exports = function buildResponseData(err, options) {
|
|
|
29
31
|
|
|
30
32
|
if (isDebugMode) {
|
|
31
33
|
fillDebugData(data, err);
|
|
32
|
-
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (data.statusCode >= 400 && data.statusCode <= 499) {
|
|
33
38
|
fillBadRequestError(data, err);
|
|
34
39
|
} else {
|
|
35
40
|
fillInternalError(data, err);
|
|
36
41
|
}
|
|
37
42
|
|
|
38
|
-
|
|
43
|
+
const safeFields = options.safeFields || [];
|
|
39
44
|
fillSafeFields(data, err, safeFields);
|
|
40
45
|
|
|
41
46
|
return data;
|
|
42
47
|
};
|
|
43
48
|
|
|
44
|
-
function serializeArrayOfErrors(errors) {
|
|
45
|
-
|
|
46
|
-
for (var ix in errors) {
|
|
47
|
-
var err = errors[ix];
|
|
48
|
-
if (typeof err !== 'object') {
|
|
49
|
-
details.push('' + err);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
var data = {};
|
|
54
|
-
cloneAllProperties(data, err);
|
|
55
|
-
delete data.statusCode;
|
|
56
|
-
details.push(data);
|
|
57
|
-
}
|
|
58
|
-
|
|
49
|
+
function serializeArrayOfErrors(errors, options) {
|
|
50
|
+
const details = errors.map(e => buildResponseData(e, options));
|
|
59
51
|
return {
|
|
60
|
-
|
|
52
|
+
statusCode: 500,
|
|
61
53
|
message: 'Failed with multiple errors, ' +
|
|
62
54
|
'see `details` for more information.',
|
|
63
55
|
details: details,
|
|
@@ -91,6 +83,8 @@ function fillSafeFields(data, err, safeFields) {
|
|
|
91
83
|
}
|
|
92
84
|
|
|
93
85
|
safeFields.forEach(function(field) {
|
|
94
|
-
|
|
86
|
+
if (err[field] !== undefined) {
|
|
87
|
+
data[field] = err[field];
|
|
88
|
+
}
|
|
95
89
|
});
|
|
96
90
|
}
|
package/package.json
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"name": "strong-error-handler",
|
|
3
3
|
"description": "Error handler for use in development and production environments.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "3.0.0",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=6"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -18,19 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"accepts": "^1.3.3",
|
|
21
|
-
"debug": "^
|
|
22
|
-
"ejs": "^2.
|
|
23
|
-
"http-status": "^1.
|
|
21
|
+
"debug": "^3.1.0",
|
|
22
|
+
"ejs": "^2.6.1",
|
|
23
|
+
"http-status": "^1.1.2",
|
|
24
24
|
"js2xmlparser": "^3.0.0",
|
|
25
|
-
"strong-globalize": "^
|
|
25
|
+
"strong-globalize": "^4.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"chai": "^
|
|
29
|
-
"eslint": "^
|
|
30
|
-
"eslint-config-loopback": "^
|
|
31
|
-
"express": "^4.
|
|
32
|
-
"mocha": "^
|
|
33
|
-
"supertest": "^3.
|
|
28
|
+
"chai": "^4.1.2",
|
|
29
|
+
"eslint": "^4.19.1",
|
|
30
|
+
"eslint-config-loopback": "^10.0.0",
|
|
31
|
+
"express": "^4.16.3",
|
|
32
|
+
"mocha": "^5.2.0",
|
|
33
|
+
"supertest": "^3.1.0"
|
|
34
34
|
},
|
|
35
35
|
"browser": {
|
|
36
36
|
"strong-error-handler": false
|
package/views/default-error.ejs
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
<html>
|
|
2
2
|
<head>
|
|
3
3
|
<meta charset='utf-8'>
|
|
4
|
-
<title
|
|
4
|
+
<title><%= data.name || data.message %></title>
|
|
5
5
|
<style><%- include style.css %></style>
|
|
6
6
|
</head>
|
|
7
7
|
<body>
|
|
8
8
|
<div id="wrapper">
|
|
9
|
-
<h1
|
|
10
|
-
<h2><em
|
|
9
|
+
<h1><%= data.name %></h1>
|
|
10
|
+
<h2><em><%= data.statusCode %></em> <%= data.message %></h2>
|
|
11
11
|
<%
|
|
12
12
|
// display all the non-standard properties
|
|
13
13
|
var standardProps = ['name', 'statusCode', 'message', 'stack'];
|
|
14
14
|
for (var prop in data) {
|
|
15
15
|
if (standardProps.indexOf(prop) == -1 && data[prop]) { %>
|
|
16
|
-
<div><b
|
|
16
|
+
<div><b><%= prop %></b>: <%= data[prop] %></div>
|
|
17
17
|
<% }
|
|
18
18
|
}
|
|
19
19
|
if (data.stack) { %>
|