Skip to content

Commit b6181ee

Browse files
authored
fix(csi-1772): added httpStatusCode to some errors. used fast-safe-stringify (#198)
* fix(csi-1772): added httpStatusCode to some errors. used fast-safe-stringify * fix(csi-1772): added CODEOWNERS * chore(snapshot): 13.1.1-snapshot.0 * fix(csi-1772): fixed PR comments * fix(csi-1772): fixed PR comments
1 parent 9c5df0f commit b6181ee

5 files changed

Lines changed: 27 additions & 25 deletions

File tree

‎CODEOWNERS‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## @global-owner1 and @global-owner2 will be requested for
77
## review when someone opens a pull request.
88
#* @global-owner1 @global-owner2
9-
* @elnyry-sam-k @bushjames @shashi165 @gibaros
9+
* @elnyry-sam-k @bushjames @shashi165 @gibaros @vijayg10 @kleyow @geka-evk @oderayi @kalinkrustev
1010

1111
## Order is important; the last matching pattern takes the most
1212
## precedence. When someone opens a pull request that only

‎package-lock.json‎

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"name": "@mojaloop/central-services-error-handling",
3-
"version": "13.1.0",
3+
"version": "13.1.1-snapshot.0",
44
"description": "Hapi error handling module",
55
"main": "src/index.js",
66
"pre-commit": [
77
"lint",
8+
"test",
89
"dep:check",
9-
"test"
10+
"audit:check"
1011
],
1112
"scripts": {
1213
"test": "npm run test:unit",
@@ -54,12 +55,12 @@
5455
"devDependencies": {
5556
"@hapi/boom": "10.0.1",
5657
"audit-ci": "^7.1.0",
57-
"npm-check-updates": "18.0.1",
58+
"npm-check-updates": "18.1.0",
5859
"nyc": "17.1.0",
5960
"pre-commit": "1.2.2",
6061
"proxyquire": "2.1.3",
6162
"replace": "^1.2.2",
62-
"sinon": "20.0.0",
63+
"sinon": "21.0.0",
6364
"standard": "17.1.2",
6465
"standard-version": "^9.5.0",
6566
"tap-spec": "^5.0.0",

‎src/errors.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ const MojaloopApiErrorCodes = {
7171
MISSING_MANDATORY_EXTENSION: { code: '3107', message: 'Missing mandatory extension parameter', httpStatusCode: 400 },
7272

7373
// identifier errors
74-
ID_NOT_FOUND: { code: '3200', message: 'Generic ID not found' },
74+
ID_NOT_FOUND: { code: '3200', message: 'Generic ID not found', httpStatusCode: 400 },
7575
DESTINATION_FSP_ERROR: { code: '3201', message: 'Destination FSP Error' },
7676
PAYER_FSP_ID_NOT_FOUND: { code: '3202', message: 'Payer FSP ID not found' },
7777
PAYEE_FSP_ID_NOT_FOUND: { code: '3203', message: 'Payee FSP ID not found' },
78-
PARTY_NOT_FOUND: { code: '3204', message: 'Party not found' },
78+
PARTY_NOT_FOUND: { code: '3204', message: 'Party not found', httpStatusCode: 400 },
7979
QUOTE_ID_NOT_FOUND: { code: '3205', message: 'Quote ID not found' },
8080
TXN_REQUEST_ID_NOT_FOUND: { code: '3206', message: 'Transaction request ID not found' },
8181
TXN_ID_NOT_FOUND: { code: '3207', message: 'Transaction ID not found' },

‎src/factory.js‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232

3333
'use strict'
3434

35-
const Enums = require('./enums')
3635
const _ = require('lodash')
36+
const stringify = require('fast-safe-stringify')
37+
const Enums = require('./enums')
3738
const { MojaloopFSPIOPError } = require('./errors')
3839

3940
/**
@@ -81,7 +82,7 @@ class FSPIOPError extends MojaloopFSPIOPError {
8182
} else if (this.cause instanceof Error) {
8283
stringifiedCause = this.cause.stack
8384
} else {
84-
stringifiedCause = JSON.stringify(this.cause)
85+
stringifiedCause = stringify(this.cause)
8586
}
8687
if (stringifiedCause) this.stack = `${this.stack}\n${stringifiedCause}`
8788
}
@@ -165,7 +166,7 @@ class FSPIOPError extends MojaloopFSPIOPError {
165166
}
166167

167168
toString () {
168-
return JSON.stringify(this.toFullErrorObject())
169+
return stringify(this.toFullErrorObject())
169170
}
170171
}
171172

@@ -187,7 +188,7 @@ const createFSPIOPError = (apiErrorCode, message, cause, replyTo, extensions, us
187188
if (!match) {
188189
match = Enums.findErrorType(apiErrorCode.code)
189190
if (!match) {
190-
throw new FSPIOPError(cause, `Factory function createFSPIOPError failed due to apiErrorCode being invalid - ${JSON.stringify(apiErrorCode)}.`, replyTo, Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, extensions)
191+
throw new FSPIOPError(cause, `Factory function createFSPIOPError failed due to apiErrorCode being invalid - ${stringify(apiErrorCode)}.`, replyTo, Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, extensions)
191192
}
192193
if (!newApiError.httpStatusCode) {
193194
newApiError.httpStatusCode = match.httpStatusCode
@@ -197,7 +198,7 @@ const createFSPIOPError = (apiErrorCode, message, cause, replyTo, extensions, us
197198
}
198199
return new FSPIOPError(cause, message, replyTo, newApiError, extensions, useDescriptionAsMessage)
199200
} else {
200-
throw new FSPIOPError(cause, `Factory function createFSPIOPError failed due to apiErrorCode being invalid - ${JSON.stringify(apiErrorCode)}.`, replyTo, Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, extensions)
201+
throw new FSPIOPError(cause, `Factory function createFSPIOPError failed due to apiErrorCode being invalid - ${stringify(apiErrorCode)}.`, replyTo, Enums.FSPIOPErrorCodes.INTERNAL_SERVER_ERROR, extensions)
201202
}
202203
}
203204

@@ -295,7 +296,7 @@ const createFSPIOPErrorFromOpenapiError = (error, replyTo) => {
295296
} else if (error.dataPath) { // replaced by instancePath, ref: https://github.com/ajv-validator/ajv/releases/tag/v8.0.0. This branch is kept here for backward compatibility.
296297
message = error.dataPath
297298
} else {
298-
message = JSON.stringify(error)
299+
message = stringify(error)
299300
}
300301
}
301302
return createFSPIOPError(fspiopError, message, replyTo)
@@ -386,7 +387,7 @@ const validateFSPIOPErrorCode = (code) => {
386387
if (result) {
387388
return result
388389
} else {
389-
throw createInternalServerFSPIOPError(`${errorMessage} - ${JSON.stringify(code)}.`)
390+
throw createInternalServerFSPIOPError(`${errorMessage} - ${stringify(code)}.`)
390391
}
391392
}
392393

@@ -411,7 +412,7 @@ const validateFSPIOPErrorGroups = (code) => {
411412
if (regex.test(codeToValidate)) {
412413
return true
413414
} else {
414-
throw createInternalServerFSPIOPError(`${errorMessage} - ${JSON.stringify(code)}.`)
415+
throw createInternalServerFSPIOPError(`${errorMessage} - ${stringify(code)}.`)
415416
}
416417
}
417418

0 commit comments

Comments
 (0)