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

Bugfix/restore handle quote error headers #168

Merged
merged 6 commits into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions audit-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@
"decision": "ignore",
"madeAt": 1582635042880,
"expiresAt": 1583239828928
},
"1179|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>node-pre-gyp>mkdirp>minimist": {
"decision": "ignore",
"madeAt": 1584465779331,
"expiresAt": 1585070560179
},
"1179|@mojaloop/event-sdk>grpc>node-pre-gyp>mkdirp>minimist": {
"decision": "ignore",
"madeAt": 1584465779331,
"expiresAt": 1585070560179
},
"1179|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>node-pre-gyp>tar>mkdirp>minimist": {
"decision": "ignore",
"madeAt": 1584465779331,
"expiresAt": 1585070560179
},
"1179|@mojaloop/event-sdk>grpc>node-pre-gyp>tar>mkdirp>minimist": {
"decision": "ignore",
"madeAt": 1584465779331,
"expiresAt": 1585070560179
},
"1179|@mojaloop/central-services-shared>@mojaloop/event-sdk>grpc>node-pre-gyp>rc>minimist": {
"decision": "ignore",
"madeAt": 1584465779331,
"expiresAt": 1585070560179
},
"1179|@mojaloop/event-sdk>grpc>node-pre-gyp>rc>minimist": {
"decision": "ignore",
"madeAt": 1584465779331,
"expiresAt": 1585070560179
}
},
"rules": {},
Expand Down
41 changes: 17 additions & 24 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
"name": "quoting-service",
"description": "Quoting Service hosted by a scheme",
"license": "Apache-2.0",
"version": "9.3.3-snapshot",
"version": "9.4.0-snapshot",
"author": "Modusbox",
"contributors": [
"James Bush <james.bush@modusbox.com>",
"Georgi Georgiev <georgi.georgiev@modusbox.com>",
"Henk Kodde <henk.kodde@modusbox.com>",
"Miguel de Barros <miguel.debarros@modusbox.com>",
"Rajiv Mothilal <rajiv.mothilal@modusbox.com>",
"Steven Oderayi <steven.oderayi@modusbox.com>"
"Steven Oderayi <steven.oderayi@modusbox.com>",
"Vassilis Barzokas <vassilis.barzokas@modusbox.com>"
],
"repository": {
"type": "git",
Expand Down
31 changes: 21 additions & 10 deletions src/model/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ class QuotesModel {
// we didnt get an endpoint for the payee dfsp!
// make an error callback to the initiator
const fspiopError = ErrorHandler.CreateFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.DESTINATION_FSP_ERROR, `No FSPIOP_CALLBACK_URL_QUOTES found for quote ${quoteId} PAYER party`, null, fspiopSource)
return this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers)
return this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, true)
}

const fullCallbackUrl = `${endpoint}/quotes/${quoteId}`
Expand Down Expand Up @@ -709,7 +709,7 @@ class QuotesModel {
const fspiopError = ErrorHandler.CreateFSPIOPErrorFromErrorInformation(error)

// Needed to add await here to prevent 'span already finished' bug
await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.DESTINATION], fspiopError, quoteId, headers, span)
await this.sendErrorCallback(headers[ENUM.Http.Headers.FSPIOP.DESTINATION], fspiopError, quoteId, headers, span, false)

return newError
} catch (err) {
Expand Down Expand Up @@ -826,7 +826,7 @@ class QuotesModel {
const childSpan = span.getChild('qs_quote_sendErrorCallback')
try {
await childSpan.audit({ headers, params: { quoteId } }, EventSdk.AuditEventAction.start)
return await this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, childSpan)
return await this.sendErrorCallback(fspiopSource, fspiopError, quoteId, headers, childSpan, true)
} catch (err) {
// any-error
// not much we can do other than log the error
Expand All @@ -845,7 +845,7 @@ class QuotesModel {
*
* @returns {promise}
*/
async sendErrorCallback (fspiopSource, fspiopError, quoteId, headers, span) {
async sendErrorCallback (fspiopSource, fspiopError, quoteId, headers, span, modifyHeaders = true) {
const envConfig = new Config()
const fspiopDest = headers[ENUM.Http.Headers.FSPIOP.DESTINATION]
try {
Expand All @@ -867,12 +867,23 @@ class QuotesModel {
this.writeLog(`Making error callback to participant '${fspiopSource}' for quoteId '${quoteId}' to ${fullCallbackUrl} for error: ${util.inspect(fspiopError.toFullErrorObject())}`)

// make an error callback
const fromSwitchHeaders = Object.assign({}, headers, {
'fspiop-destination': fspiopSource,
'fspiop-source': ENUM.Http.Headers.FSPIOP.SWITCH.value,
'fspiop-http-method': ENUM.Http.RestMethods.PUT,
'fspiop-uri': fspiopUri
})
let fromSwitchHeaders

// modify/set the headers only in case it is explicitly requested to do so
// as this part needs to cover two different cases:
// 1. (do not modify them) when the Switch needs to relay an error, e.g. from a DFSP to another
// 2. (modify/set them) when the Switch needs send errors that are originating in the Switch, e.g. to send an error back to the caller
if (modifyHeaders === true) {
fromSwitchHeaders = Object.assign({}, headers, {
'fspiop-destination': fspiopSource,
'fspiop-source': ENUM.Http.Headers.FSPIOP.SWITCH.value,
'fspiop-http-method': ENUM.Http.RestMethods.PUT,
'fspiop-uri': fspiopUri
})
} else {
fromSwitchHeaders = Object.assign({}, headers)
}

let opts = {
method: ENUM.Http.RestMethods.PUT,
url: fullCallbackUrl,
Expand Down
4 changes: 2 additions & 2 deletions test/unit/model/quotes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ describe('QuotesModel', () => {
const result = await quotesModel.handleException('payeefsp', mockData.quoteId, error, mockData.headers, mockSpan)

// Assert
expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan)
expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan, true)
expect(result).toBe(true)
expect(mockChildSpan.finish).toHaveBeenCalledTimes(1)
})
Expand All @@ -1852,7 +1852,7 @@ describe('QuotesModel', () => {
await quotesModel.handleException('payeefsp', mockData.quoteId, error, mockData.headers, mockSpan)

// Assert
expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan)
expect(quotesModel.sendErrorCallback).toHaveBeenCalledWith('payeefsp', expectedError, mockData.quoteId, mockData.headers, mockChildSpan, true)
expect(quotesModel.writeLog).toHaveBeenCalledTimes(1)
expect(mockChildSpan.finish).toHaveBeenCalledTimes(1)
})
Expand Down