From a93c8b9f222f8addb23f5f8dffaf4133636ac2d6 Mon Sep 17 00:00:00 2001 From: Steven Oderayi Date: Mon, 10 Feb 2020 13:13:14 +0100 Subject: [PATCH] Fix for #1173 - GET /quotes for unknown quote ID error response is 1001 instead of 3205 (#139) * Bump version to 9.0.0-snapshot * Fix response codes for PUT /quotes/{id} and PUT /quotes/{id}/error from 202 to 200 * Update dependencies. Freeze json-rules-engine due to breaking changes * Bump version to 9.1.0 * Remove hard-coded response codes in test * Return error 3000 - Generic client error and not 1001 on 404 errors * Update dependencies * Fix span bug * Update cs-shared --- .ncurc.json | 3 +- package-lock.json | 291 ++++++++++++++++++++----- package.json | 6 +- src/handlers/quotes/{id}.js | 4 +- src/lib/http.js | 6 +- src/model/quotes.js | 3 +- test/unit/handlers/quotes/{id}.test.js | 9 +- 7 files changed, 260 insertions(+), 62 deletions(-) diff --git a/.ncurc.json b/.ncurc.json index 6dacf9b6..9de9bdae 100644 --- a/.ncurc.json +++ b/.ncurc.json @@ -1,6 +1,7 @@ { "reject": [ "@hapi/hapi", - "@hapi/good" + "@hapi/good", + "json-rules-engine" ] } diff --git a/package-lock.json b/package-lock.json index a1bba0cc..2c9fadd6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quoting-service", - "version": "8.8.2-snapshot", + "version": "9.1.0-snapshot", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1523,23 +1523,32 @@ } } }, + "@mojaloop/central-services-metrics": { + "version": "8.8.0", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-metrics/-/central-services-metrics-8.8.0.tgz", + "integrity": "sha512-rkwSHs2TaKsQ+xwh/KP5nv8lBbXpfQOq+0HfVbDpiI85d92yMmfhQFlBZ8ypxxXHejHP2cfUcroGmZ7ZHdk9Ug==", + "requires": { + "prom-client": "11.5.3" + } + }, "@mojaloop/central-services-shared": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/@mojaloop/central-services-shared/-/central-services-shared-8.8.2.tgz", - "integrity": "sha512-/qP+/yyX8ExzojJfiU62DXfaMxGuovwEGU1FdT5aaA69P3jXcKrOK5ztfZJivIs1xAlf/xiiZlkMr2IGBZ/QfQ==", + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-shared/-/central-services-shared-9.1.1.tgz", + "integrity": "sha512-ZY15we/VUcSbRcudwK92Qy+1HFLrsFALllkIaHnX9z8dgX8LVCcbM415HJMdeQUrDjx5eLsaXw8IW9rsXa+f+g==", "requires": { "@hapi/catbox": "10.2.3", "@hapi/catbox-memory": "5.0.0", "@mojaloop/central-services-error-handling": "8.7.0", "@mojaloop/central-services-logger": "8.6.0", + "@mojaloop/central-services-metrics": "8.8.0", "@mojaloop/event-sdk": "8.8.1-snapshot.2", - "axios": "0.19.1", + "axios": "0.19.2", "base64url": "3.0.1", "clone": "2.1.2", "data-urls": "2.0.0", "immutable": "3.8.2", "lodash": "4.17.15", - "mustache": "3.2.1", + "mustache": "4.0.0", "raw-body": "2.4.1" }, "dependencies": { @@ -1589,14 +1598,6 @@ "winston": "3.2.1" } }, - "axios": { - "version": "0.19.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.1.tgz", - "integrity": "sha512-Yl+7nfreYKaLRvAvjNPkvfjnQHJM1yLBY3zhqAwcJSwR/6ETkanUgylgtIvkvz0xJ+p/vZuNw8X7Hnb7Whsbpw==", - "requires": { - "follow-redirects": "1.5.10" - } - }, "data-urls": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-2.0.0.tgz", @@ -1922,12 +1923,104 @@ } }, "@types/jest": { - "version": "24.9.1", - "resolved": "https://registry.npmjs.org/@types/jest/-/jest-24.9.1.tgz", - "integrity": "sha512-Fb38HkXSVA4L8fGKEZ6le5bB8r6MRWlOCZbVuWZcmOMSCd2wCYOwN1ibj8daIoV9naq7aaOZjrLCoCMptKU/4Q==", + "version": "25.1.2", + "resolved": "https://registry.npmjs.org/@types/jest/-/jest-25.1.2.tgz", + "integrity": "sha512-EsPIgEsonlXmYV7GzUqcvORsSS9Gqxw/OvkGwHfAdpjduNRxMlhsav0O5Kb0zijc/eXSO/uW6SJt9nwull8AUQ==", "dev": true, "requires": { - "jest-diff": "^24.3.0" + "jest-diff": "^25.1.0", + "pretty-format": "^25.1.0" + }, + "dependencies": { + "@jest/types": { + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-25.1.0.tgz", + "integrity": "sha512-VpOtt7tCrgvamWZh1reVsGADujKigBUFTi19mlRjqEGsE8qH4r3s+skY33dNdXOwyZIvuftZ5tqdF1IgsMejMA==", + "dev": true, + "requires": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^1.1.1", + "@types/yargs": "^15.0.0", + "chalk": "^3.0.0" + } + }, + "@types/yargs": { + "version": "15.0.3", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz", + "integrity": "sha512-XCMQRK6kfpNBixHLyHUsGmXrpEmFFxzMrcnSXFMziHd8CoNJo8l16FkHyQq4x+xbM7E2XL83/O78OD8u+iZTdQ==", + "dev": true, + "requires": { + "@types/yargs-parser": "*" + } + }, + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "pretty-format": { + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-25.1.0.tgz", + "integrity": "sha512-46zLRSGLd02Rp+Lhad9zzuNZ+swunitn8zIpfD2B4OPCRLXbM87RJT2aBLBWYOznNUML/2l/ReMyWNC80PJBUQ==", + "dev": true, + "requires": { + "@jest/types": "^25.1.0", + "ansi-regex": "^5.0.0", + "ansi-styles": "^4.0.0", + "react-is": "^16.12.0" + } + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } } }, "@types/long": { @@ -2501,6 +2594,11 @@ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-5.0.0.tgz", "integrity": "sha512-KWTu6ZMVk9sxlDJQh2YH1UOnfDP8O8TpxUxgQG/vKASoSnEjK9aVuOueFaPcQEYQ5fyNXNTOYwYw3099RYebWg==" }, + "bintrees": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/bintrees/-/bintrees-1.0.1.tgz", + "integrity": "sha1-DmVcm5wkNeqraL9AJyJtK1WjRSQ=" + }, "blipp": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/blipp/-/blipp-4.0.1.tgz", @@ -3450,9 +3548,9 @@ "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" }, "diff-sequences": { - "version": "24.9.0", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-24.9.0.tgz", - "integrity": "sha512-Dj6Wk3tWyTE+Fo1rW8v0Xhwk80um6yFYKbuAxc9c3EZxIHFDYwbi34Uk42u1CdnIiVorvt4RmlSDjIPyzGC2ew==", + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-25.1.0.tgz", + "integrity": "sha512-nFIfVk5B/NStCsJ+zaPO4vYuLjlzQ6uFvPxzYyHlejNZ/UGa7G/n7peOXVrVNvRuyfstt+mZQYGpjxg9Z6N8Kw==", "dev": true }, "djv": { @@ -7110,15 +7208,112 @@ } }, "jest-diff": { - "version": "24.9.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-24.9.0.tgz", - "integrity": "sha512-qMfrTs8AdJE2iqrTp0hzh7kTd2PQWrsFyj9tORoKmu32xjPjeE4NyjVRDz8ybYwqS2ik8N4hsIpiVTyFeo2lBQ==", + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-25.1.0.tgz", + "integrity": "sha512-nepXgajT+h017APJTreSieh4zCqnSHEJ1iT8HDlewu630lSJ4Kjjr9KNzm+kzGwwcpsDE6Snx1GJGzzsefaEHw==", "dev": true, "requires": { - "chalk": "^2.0.1", - "diff-sequences": "^24.9.0", - "jest-get-type": "^24.9.0", - "pretty-format": "^24.9.0" + "chalk": "^3.0.0", + "diff-sequences": "^25.1.0", + "jest-get-type": "^25.1.0", + "pretty-format": "^25.1.0" + }, + "dependencies": { + "@jest/types": { + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-25.1.0.tgz", + "integrity": "sha512-VpOtt7tCrgvamWZh1reVsGADujKigBUFTi19mlRjqEGsE8qH4r3s+skY33dNdXOwyZIvuftZ5tqdF1IgsMejMA==", + "dev": true, + "requires": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^1.1.1", + "@types/yargs": "^15.0.0", + "chalk": "^3.0.0" + } + }, + "@types/yargs": { + "version": "15.0.3", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz", + "integrity": "sha512-XCMQRK6kfpNBixHLyHUsGmXrpEmFFxzMrcnSXFMziHd8CoNJo8l16FkHyQq4x+xbM7E2XL83/O78OD8u+iZTdQ==", + "dev": true, + "requires": { + "@types/yargs-parser": "*" + } + }, + "ansi-regex": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", + "integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==", + "dev": true + }, + "ansi-styles": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", + "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "dev": true, + "requires": { + "@types/color-name": "^1.1.1", + "color-convert": "^2.0.1" + } + }, + "chalk": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz", + "integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==", + "dev": true, + "requires": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + } + }, + "color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "requires": { + "color-name": "~1.1.4" + } + }, + "color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true + }, + "jest-get-type": { + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-25.1.0.tgz", + "integrity": "sha512-yWkBnT+5tMr8ANB6V+OjmrIJufHtCAqI5ic2H40v+tRqxDmE0PGnIiTyvRWFOMtmVHYpwRqyazDbTnhpjsGvLw==", + "dev": true + }, + "pretty-format": { + "version": "25.1.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-25.1.0.tgz", + "integrity": "sha512-46zLRSGLd02Rp+Lhad9zzuNZ+swunitn8zIpfD2B4OPCRLXbM87RJT2aBLBWYOznNUML/2l/ReMyWNC80PJBUQ==", + "dev": true, + "requires": { + "@jest/types": "^25.1.0", + "ansi-regex": "^5.0.0", + "ansi-styles": "^4.0.0", + "react-is": "^16.12.0" + } + }, + "supports-color": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", + "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "dev": true, + "requires": { + "has-flag": "^4.0.0" + } + } } }, "jest-docblock": { @@ -9923,9 +10118,9 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "mustache": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/mustache/-/mustache-3.2.1.tgz", - "integrity": "sha512-RERvMFdLpaFfSRIEe632yDm5nsd0SDKn8hGmcUwswnyiE5mtdZLDybtHAz6hjJhawokF0hXvGLtx9mrQfm6FkA==" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.0.0.tgz", + "integrity": "sha512-FJgjyX/IVkbXBXYUwH+OYwQKqWpFPLaLVESd70yHjSDunwzV2hZOoTBvPf4KLoxesUzzyfTH6F784Uqd7Wm5yA==" }, "mute-stream": { "version": "0.0.8", @@ -11614,6 +11809,14 @@ "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true }, + "prom-client": { + "version": "11.5.3", + "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-11.5.3.tgz", + "integrity": "sha512-iz22FmTbtkyL2vt0MdDFY+kWof+S9UB/NACxSn2aJcewtw+EERsen0urSkZ2WrHseNdydsvcxCTAnPcSMZZv4Q==", + "requires": { + "tdigest": "^0.1.1" + } + }, "promise-inflight": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", @@ -13258,6 +13461,14 @@ "resolved": "https://registry.npmjs.org/tarn/-/tarn-2.0.0.tgz", "integrity": "sha512-7rNMCZd3s9bhQh47ksAQd92ADFcJUjjbyOvyFjNLwTPpGieFHMC84S+LOzw0fx1uh6hnDz/19r8CPMnIjJlMMA==" }, + "tdigest": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/tdigest/-/tdigest-0.1.1.tgz", + "integrity": "sha1-Ljyyw56kSeVdHmzZEReszKRYgCE=", + "requires": { + "bintrees": "1.0.1" + } + }, "term-size": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/term-size/-/term-size-1.2.0.tgz", @@ -14094,24 +14305,6 @@ "y18n": "^3.2.0" } }, - "yargs-parser": { - "version": "16.1.0", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-16.1.0.tgz", - "integrity": "sha512-H/V41UNZQPkUMIT5h5hiwg4QKIY1RPvoBV4XcjUbRM8Bk2oKqqyZ0DIEbTFZB0XjbtSPG8SAa/0DxCQmiRgzKg==", - "dev": true, - "requires": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" - }, - "dependencies": { - "camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", - "dev": true - } - } - }, "yargs-unparser": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-1.5.0.tgz", diff --git a/package.json b/package.json index 4f5b3ce0..9118bde5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "quoting-service", "description": "Quoting Service hosted by a scheme", "license": "Apache-2.0", - "version": "8.8.2-snapshot", + "version": "9.1.0-snapshot", "author": "Modusbox", "contributors": [ "James Bush ", @@ -59,7 +59,7 @@ "@hapi/hapi": "18.4.0", "@mojaloop/central-services-error-handling": "8.7.0", "@mojaloop/central-services-logger": "8.6.0", - "@mojaloop/central-services-shared": "8.8.2", + "@mojaloop/central-services-shared": "9.1.1", "@mojaloop/event-sdk": "8.7.0", "@mojaloop/ml-number": "8.2.0", "axios": "0.19.2", @@ -77,7 +77,7 @@ "rc": "1.2.8" }, "devDependencies": { - "@types/jest": "24.9.1", + "@types/jest": "25.1.2", "eslint": "6.8.0", "jest": "25.1.0", "jest-junit": "10.0.0", diff --git a/src/handlers/quotes/{id}.js b/src/handlers/quotes/{id}.js index cf601783..01ca84da 100644 --- a/src/handlers/quotes/{id}.js +++ b/src/handlers/quotes/{id}.js @@ -84,7 +84,7 @@ module.exports = { await model.handleException(fspiopSource, quoteId, err, request.headers, span) } finally { // eslint-disable-next-line no-unsafe-finally - return h.response().code(202) + return h.response().code(Enum.Http.ReturnCodes.ACCEPTED.CODE) } }, @@ -127,7 +127,7 @@ module.exports = { await model.handleException(fspiopSource, quoteId, err, request.headers, span) } finally { // eslint-disable-next-line no-unsafe-finally - return h.response().code(202) + return h.response().code(Enum.Http.ReturnCodes.OK.CODE) } } } diff --git a/src/lib/http.js b/src/lib/http.js index 0736c0d3..c50b8e28 100644 --- a/src/lib/http.js +++ b/src/lib/http.js @@ -60,8 +60,10 @@ async function httpRequest (opts, fspiopSource) { res = await axios.request(opts) body = await res.data } catch (e) { - throw ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_COMMUNICATION_ERROR, - 'Network error', + const [fspiopErrorType, fspiopErrorDescr] = e.response && e.response.status === 404 + ? [ErrorHandler.Enums.FSPIOPErrorCodes.CLIENT_ERROR, 'Not found'] + : [ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_COMMUNICATION_ERROR, 'Network error'] + throw ErrorHandler.CreateFSPIOPError(fspiopErrorType, fspiopErrorDescr, `${getStackOrInspect(e)}. Opts: ${util.inspect(opts)}`, fspiopSource) } diff --git a/src/model/quotes.js b/src/model/quotes.js index 98fe7ecc..468373a7 100644 --- a/src/model/quotes.js +++ b/src/model/quotes.js @@ -707,7 +707,8 @@ class QuotesModel { // create a new object to represent the error const fspiopError = ErrorHandler.CreateFSPIOPErrorFromErrorInformation(error) - this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.SOURCE], fspiopError, quoteId, headers, span) + // Needed to add await here to prevent 'span already finished' bug + await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.SOURCE], fspiopError, quoteId, headers, span) return newError } catch (err) { diff --git a/test/unit/handlers/quotes/{id}.test.js b/test/unit/handlers/quotes/{id}.test.js index cd3f4187..9db97652 100644 --- a/test/unit/handlers/quotes/{id}.test.js +++ b/test/unit/handlers/quotes/{id}.test.js @@ -32,6 +32,7 @@ jest.mock('@mojaloop/central-services-logger') jest.mock('../../../../src/model/quotes') +const Enum = require('@mojaloop/central-services-shared').Enum const QuotesHandler = require('../../../../src/handlers/quotes/{id}') const QuotesModel = require('../../../../src/model/quotes') const { baseMockRequest } = require('../../../util/helper') @@ -58,7 +59,7 @@ describe('/quotes/{id}', () => { expect(QuotesModel).toHaveBeenCalledTimes(1) const mockQuoteInstance = QuotesModel.mock.instances[0] expect(mockQuoteInstance.handleQuoteGet).toHaveBeenCalledTimes(1) - expect(code).toHaveBeenCalledWith(202) + expect(code).toHaveBeenCalledWith(Enum.Http.ReturnCodes.ACCEPTED.CODE) }) it('handles an error with the model', async () => { @@ -85,7 +86,7 @@ describe('/quotes/{id}', () => { // Assert expect(QuotesModel).toHaveBeenCalledTimes(1) expect(handleException).toHaveBeenCalledTimes(1) - expect(code).toHaveBeenCalledWith(202) + expect(code).toHaveBeenCalledWith(Enum.Http.ReturnCodes.ACCEPTED.CODE) }) }) @@ -108,7 +109,7 @@ describe('/quotes/{id}', () => { expect(QuotesModel).toHaveBeenCalledTimes(1) const mockQuoteInstance = QuotesModel.mock.instances[0] expect(mockQuoteInstance.handleQuoteUpdate).toHaveBeenCalledTimes(1) - expect(code).toHaveBeenCalledWith(202) + expect(code).toHaveBeenCalledWith(Enum.Http.ReturnCodes.OK.CODE) }) it('handles an error with the model', async () => { @@ -135,7 +136,7 @@ describe('/quotes/{id}', () => { // Assert expect(QuotesModel).toHaveBeenCalledTimes(1) expect(handleException).toHaveBeenCalledTimes(1) - expect(code).toHaveBeenCalledWith(202) + expect(code).toHaveBeenCalledWith(Enum.Http.ReturnCodes.OK.CODE) }) }) })