Skip to content

Commit

Permalink
feat: remove httpStatusCode b/w compat property
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jul 10, 2024
1 parent 14f3fb6 commit dca780d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
12 changes: 0 additions & 12 deletions src/server/__snapshots__/getDefaultRouter.test.ts.snap

This file was deleted.

5 changes: 1 addition & 4 deletions src/server/genericErrorMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let formatError: GenericErrorMiddlewareCfg['formatError']

/**
* Generic error handler.
* Returns HTTP code based on err.data.httpStatusCode (default to 500).
* Returns HTTP code based on err.data.backendResponseStatusCode (default to 500).
* Sends json payload as ErrorResponse, transformed via errorSharedUtil.
*/
export function genericErrorMiddleware(
Expand Down Expand Up @@ -86,9 +86,6 @@ export function respondWithError(req: BackendRequest, res: BackendResponse, err:

httpError.data.errorId = errorId
httpError.data.backendResponseStatusCode ||= 500 // default to 500
// httpStatusCode is for backwards-compatibility
// Otherwise, it breaks the _isHttpErrorResponse function check, and error get formatted/detected wrongly
httpError.data['httpStatusCode'] = httpError.data.backendResponseStatusCode
httpError.data.headersSent = headersSent || undefined
_filterUndefinedValues(httpError.data, true)

Expand Down
25 changes: 12 additions & 13 deletions src/server/validation/validateMiddleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ test('validateBody', async () => {
expect(err.cause.message).not.toContain(pw)
expect(err.cause.message).toContain('REDACTED')
expect(err.cause).toMatchInlineSnapshot(`
{
"data": {
"backendResponseStatusCode": 400,
"errors": [],
"httpStatusCode": 400,
"objectName": "request body",
"userFriendly": true,
},
"message": "request body/pw must NOT have fewer than 8 characters
Input: { pw: 'REDACTED' }",
"name": "AppError",
}
`)
{
"data": {
"backendResponseStatusCode": 400,
"errors": [],
"objectName": "request body",
"userFriendly": true,
},
"message": "request body/pw must NOT have fewer than 8 characters
Input: { pw: 'REDACTED' }",
"name": "AppError",
}
`)
})
1 change: 0 additions & 1 deletion src/server/validation/validateRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ test('validateRequest', async () => {
{
"data": {
"backendResponseStatusCode": 400,
"httpStatusCode": 400,
"joiValidationErrorItems": [],
"joiValidationObjectName": "request body",
},
Expand Down

0 comments on commit dca780d

Please sign in to comment.