@defra/lis-infra-ui-services 0.37.0 → 0.38.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/README.md +1 -1
- package/package.json +1 -1
- package/src/errors/index.js +8 -3
- package/src/errors/index.test.js +15 -6
package/README.md
CHANGED
|
@@ -180,7 +180,7 @@ The main entry point (`@defra/lis-infra-ui-services`) exports `buildMicrositePat
|
|
|
180
180
|
| 503 | `service-unavailable` |
|
|
181
181
|
| anything else | `problem-with-service` |
|
|
182
182
|
|
|
183
|
-
5xx responses are logged at `error`, and 4xx responses other than 401, 403 and 404 at `warn`, each with the error object
|
|
183
|
+
5xx responses are logged at `error`, and 4xx responses other than 401, 403 and 404 at `warn`, each with the error object and the ECS fields `http.request.method`, `url.path` and `http.response.status_code`. Boom messages are logged, so application code must not put user-supplied text in them.
|
|
184
184
|
|
|
185
185
|
```js
|
|
186
186
|
import { catchAll } from '@defra/lis-infra-ui-services/errors'
|
package/package.json
CHANGED
package/src/errors/index.js
CHANGED
|
@@ -64,11 +64,16 @@ function logFailure(request, statusCode) {
|
|
|
64
64
|
return
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
//
|
|
67
|
+
// Native ECS keys: hubs register hapi-pino on the shared logger, whose
|
|
68
|
+
// req/res serialisers expect real HTTP objects (and null the status of a
|
|
69
|
+
// plain one). request.path deliberately omits the query string.
|
|
68
70
|
const context = {
|
|
69
71
|
err: getError(response, statusCode),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
http: {
|
|
73
|
+
request: { method: request.method },
|
|
74
|
+
response: { status_code: statusCode }
|
|
75
|
+
},
|
|
76
|
+
url: { path: request.path }
|
|
72
77
|
}
|
|
73
78
|
|
|
74
79
|
if (isServerError) {
|
package/src/errors/index.test.js
CHANGED
|
@@ -107,8 +107,11 @@ test('catchAll logs server errors and renders the problem with the service page'
|
|
|
107
107
|
assert.deepEqual(logger.error.mock.calls[0], [
|
|
108
108
|
{
|
|
109
109
|
err: request.response,
|
|
110
|
-
|
|
111
|
-
|
|
110
|
+
http: {
|
|
111
|
+
request: { method: 'get' },
|
|
112
|
+
response: { status_code: statusCodes.internalServerError }
|
|
113
|
+
},
|
|
114
|
+
url: { path: '/mock-path' }
|
|
112
115
|
},
|
|
113
116
|
'Request failed'
|
|
114
117
|
])
|
|
@@ -129,8 +132,11 @@ test.each([statusCodes.badRequest, statusCodes.unprocessableEntity])(
|
|
|
129
132
|
assert.deepEqual(logger.warn.mock.calls[0], [
|
|
130
133
|
{
|
|
131
134
|
err: request.response,
|
|
132
|
-
|
|
133
|
-
|
|
135
|
+
http: {
|
|
136
|
+
request: { method: 'get' },
|
|
137
|
+
response: { status_code: statusCode }
|
|
138
|
+
},
|
|
139
|
+
url: { path: '/mock-path' }
|
|
134
140
|
},
|
|
135
141
|
'Request rejected'
|
|
136
142
|
])
|
|
@@ -214,8 +220,11 @@ test('catchAll logs the error behind plain 500 responses before continuing', ()
|
|
|
214
220
|
assert.deepEqual(logger.error.mock.calls[0], [
|
|
215
221
|
{
|
|
216
222
|
err: sourceError,
|
|
217
|
-
|
|
218
|
-
|
|
223
|
+
http: {
|
|
224
|
+
request: { method: 'post' },
|
|
225
|
+
response: { status_code: statusCodes.internalServerError }
|
|
226
|
+
},
|
|
227
|
+
url: { path: '/plain' }
|
|
219
228
|
},
|
|
220
229
|
'Request failed'
|
|
221
230
|
])
|