-
Notifications
You must be signed in to change notification settings - Fork 84
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
feat: add bulk error handling notification callbacks #911
Conversation
kleyow
commented
Jul 22, 2022
•
edited
Loading
edited
- Add duplicate request handling for bulk transfer request
- Add error notification handling for failed bulk transfer/failed validation/unexpected db errors.
- Improve participant validation for bulk transfers
src/handlers/bulk/prepare/handler.js
Outdated
if (hasDuplicateId && hasDuplicateHash) { | ||
Logger.isErrorEnabled && Logger.error(Util.breadcrumb(location, `callbackErrorModified--${actionLetter}1`)) | ||
|
||
const fspiopError = ErrorHandler.Factory.createFSPIOPError(ErrorHandler.Enums.FSPIOPErrorCodes.MODIFIED_REQUEST, 'Bulk transfer prepare duplicate') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior on duplicate requests is that:
- If the ID (here bulkTransferID) and the message hash matches, it is essentially a "resend", so in this case - "IF the bulkTransfer is in a final state (final states for bulk - COMPLETED, REJECTED), we treat it as a GET /bulkTransfers/{ID} call and send out a PUT /bulkTransfers/{ID} with the same payload as that of a final notification. If however, the bulkTransfer is in a non-final state (the rest in the BulkTransferState enum - RECEIVED, PENDING, ACCEPTED, PROCESSING), then we do not send anything back, allowing the final notification to be sent once processing is done."
- On a bulkTransfer if a previously used ID is used but the message is different or modified (hash is different), then we send out the error callback saying its a "modified request"
Here's the section in the FSPIOP API spec discussing this behavior: https://docs.mojaloop.io/api/fspiop/v1.1/api-definition.html#duplicate-analysis-in-server-on-receiving-a-http-post-request
src/handlers/bulk/prepare/handler.js
Outdated
// Check to see if the resend is coming from a participant of involved | ||
// with the bulk transfer to avoid potential data leakage. | ||
const participants = await BulkTransferService.getParticipantsById(bulkTransferId) | ||
if (![participants.payeeFsp, participants.payerFsp].includes(message.value.from)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one and the next check should be unreachable code, isn't it? "hasDuplicateHash" should indicate that the headers and payload are exactly same as before.. So the check that this is coming from the same Payer FSP as before should already be covered there..
src/handlers/bulk/prepare/handler.js
Outdated
params.message.value.content.uriParams = { id: bulkTransferId } | ||
// Resend should typically only occur by the Payer FSP, but lets | ||
// handle if the same request is somehow sent by the Payer FSP. | ||
const isPayeeRequest = participants.payeeFsp === message.value.from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't be needed, isn't it? (handled by "hasDuplicateHash")