@defra/lis-infra-ui-services 0.11.0 → 0.12.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra/lis-infra-ui-services",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "UI-Services shared definitions for the livestock taxonomy topology.",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -19,7 +19,7 @@ function statusCodeMessage(statusCode) {
19
19
  }
20
20
 
21
21
  function getStatusCode(response) {
22
- return response?.output?.statusCode ?? response?.statusCode
22
+ return response?.statusCode ?? response?.output?.statusCode
23
23
  }
24
24
 
25
25
  function getLogMessage(response, statusCode) {
@@ -83,6 +83,31 @@ test('catchAll logs and renders generic content for server errors', () => {
83
83
  assert.deepEqual(logger.error.mock.calls[0], ['Mock error stack'])
84
84
  })
85
85
 
86
+ test('catchAll prefers a client-attached statusCode over a boomified 500', () => {
87
+ const request = {
88
+ response: {
89
+ isBoom: true,
90
+ statusCode: statusCodes.notFound,
91
+ stack: 'Mock error stack',
92
+ output: { statusCode: statusCodes.internalServerError }
93
+ }
94
+ }
95
+ const toolkit = createToolkit()
96
+
97
+ catchAll(request, toolkit)
98
+
99
+ assert.deepEqual(toolkit.view.mock.calls[0], [
100
+ 'error/index',
101
+ {
102
+ pageTitle: 'Page not found',
103
+ heading: statusCodes.notFound,
104
+ message: 'Page not found'
105
+ }
106
+ ])
107
+ assert.deepEqual(toolkit.code.mock.calls[0], [statusCodes.notFound])
108
+ assert.equal(logger.error.mock.calls.length, 0)
109
+ })
110
+
86
111
  test('catchAll logs plain 500 responses before continuing', () => {
87
112
  const toolkit = createToolkit()
88
113
  const request = {