Skip to content

Commit

Permalink
fix(csi-550): add logs to QuotesModel (#351)
Browse files Browse the repository at this point in the history
* fix(csi-550): add logs to QuotesModel

* fix(csi-550): add logs to QuotesModel

* fix(csi-550): add logs to QuotesModel

* fix(csi-550): add logs to QuotesModel

* chore(snapshot): 15.8.0-snapshot.37

* fix(csi-550): added logs to QuotesModel.forwardQuoteRequest()

* chore(snapshot): 15.8.0-snapshot.38

* fix(csi-550): improved logs in QuotesModel

* chore(snapshot): 15.8.0-snapshot.39

* fix(csi-550): improved logs in QuotesModel for handleQuoteRequest

* chore(snapshot): 15.8.0-snapshot.40
  • Loading branch information
geka-evk authored Aug 30, 2024
1 parent 0d8fc24 commit 797b63f
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 158 deletions.
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

0 comments on commit 797b63f

Please sign in to comment.