Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(csi-550): add logs to QuotesModel #351

Merged
merged 11 commits into from
Aug 30, 2024
3 changes: 2 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"allowlist": [
"GHSA-qgmg-gppg-76g5", // https://github.com/advisories/GHSA-qgmg-gppg-76g5 Mock data generator for swagger api, not a security concern at this time.
"GHSA-c429-5p7v-vgjp", // https://github.com/advisories/GHSA-c429-5p7v-vgjp
"GHSA-8hc4-vh64-cxmj" // https://github.com/advisories/GHSA-8hc4-vh64-cxmj
"GHSA-8hc4-vh64-cxmj", // https://github.com/advisories/GHSA-8hc4-vh64-cxmj
"GHSA-952p-6rrq-rcjv" // https://github.com/advisories/GHSA-952p-6rrq-rcjv
]
}
38 changes: 19 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "quoting-service",
"description": "Quoting Service hosted by a scheme",
"license": "Apache-2.0",
"version": "15.8.0-snapshot.36",
"version": "15.8.0-snapshot.40",
"author": "ModusBox",
"contributors": [
"Georgi Georgiev <georgi.georgiev@modusbox.com>",
Expand Down Expand Up @@ -107,17 +107,17 @@
"@hapi/vision": "7.0.3",
"@mojaloop/central-services-error-handling": "13.0.1",
"@mojaloop/central-services-health": "15.0.0",
"@mojaloop/central-services-logger": "11.5.0",
"@mojaloop/central-services-logger": "11.5.1",
"@mojaloop/central-services-metrics": "12.0.8",
"@mojaloop/central-services-shared": "18.5.0-snapshot.2",
"@mojaloop/central-services-stream": "11.3.1",
"@mojaloop/event-sdk": "14.1.1",
"@mojaloop/inter-scheme-proxy-cache-lib": "2.2.0",
"@mojaloop/inter-scheme-proxy-cache-lib": "2.3.0",
"@mojaloop/ml-number": "11.2.4",
"@mojaloop/sdk-standard-components": "18.1.0",
"ajv": "8.17.1",
"ajv-keywords": "5.1.0",
"axios": "1.7.4",
"axios": "1.7.5",
"blipp": "4.0.2",
"commander": "12.1.0",
"event-stream": "4.0.1",
Expand Down
16 changes: 12 additions & 4 deletions src/lib/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
--------------
******/

const http = require('node:http')
const util = require('node:util')
const axios = require('axios')
const util = require('util')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const http = require('http')

const { logger } = require('../lib')
const { getStackOrInspect } = require('../lib/util')

axios.defaults.httpAgent = new http.Agent({ keepAlive: true })
Expand All @@ -59,11 +60,15 @@ async function httpRequest (opts, fspiopSource) {
// need to wrap the request below in a `try catch` to handle network errors
let res
let body
const log = logger.child({ context: 'httpRequest', fspiopSource, opts })
log.debug('httpRequest is started...')

try {
res = await axios.request(opts)
body = await res.data
log.debug('httpRequest is finished', { body })
} catch (e) {
log.error('httpRequest is failed due to error:', e)
const [fspiopErrorType, fspiopErrorDescr] = e.response && e.response.status === 404
? [ErrorHandler.Enums.FSPIOPErrorCodes.CLIENT_ERROR, 'Not found']
: [ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_COMMUNICATION_ERROR, 'Network error']
Expand All @@ -74,18 +79,21 @@ async function httpRequest (opts, fspiopSource) {

// handle non network related errors below
if (res.status < 200 || res.status >= 300) {
const errObj = util.inspect({
const errObj = {
opts,
status: res.status,
statusText: res.statusText,
body
})
}
log.warn('httpRequest returned non-success status code', errObj)

throw ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_COMMUNICATION_ERROR,
'Non-success response in HTTP request',
`${errObj}`,
fspiopSource)
}

return body
}

module.exports = {
Expand Down
Loading