-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add PUT /thirdpartyRequests/transactions/{id}/error (#41)
- Loading branch information
Showing
10 changed files
with
498 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/server/handlers/thirdpartyRequests/transactions/{ID}/error.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/***** | ||
License | ||
-------------- | ||
Copyright © 2020 Mojaloop Foundation The Mojaloop files are made available by the Mojaloop Foundation | ||
under the Apache License, Version 2.0 (the 'License') and you may not | ||
use these files except in compliance with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in | ||
writing, the Mojaloop files are distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS | ||
OF ANY KIND, either express or implied. See the License for the specific language governing | ||
permissions and limitations under the License. Contributors | ||
-------------- | ||
This is the official list of the Mojaloop project contributors for this file. Names of the original | ||
copyright holders (individuals or organizations) should be listed with a '*' in the first column. | ||
People who have contributed from an organization can be listed under the organization that actually | ||
holds the copyright for their contributions (see the Gates Foundation organization for an example). | ||
Those individuals should have their names indented and be marked with a '-'. Email address can be | ||
added optionally within square brackets <email>. | ||
* Gates Foundation | ||
- Name Surname <name.surname@gatesfoundation.com> | ||
- Kevin Leyow <kevin.leyow@modusbox.com> | ||
-------------- | ||
******/ | ||
'use strict' | ||
|
||
import { Request, ResponseToolkit, ResponseObject } from '@hapi/hapi' | ||
import Logger from '@mojaloop/central-services-logger' | ||
import { ReformatFSPIOPError, APIErrorObject } from '@mojaloop/central-services-error-handling' | ||
import { Enum } from '@mojaloop/central-services-shared' | ||
import { AuditEventAction } from '@mojaloop/event-sdk' | ||
import { Transactions } from '~/domain/thirdpartyRequests' | ||
import { getSpanTags } from '~/shared/util' | ||
|
||
/** | ||
* summary: ThirdpartyTransactionRequestsError | ||
* description: The HTTP request PUT /thirdpartyRequests/transactions/{ID}/error is used to inform a thirdparty | ||
* of a transaction error. | ||
* parameters: body, accept, content-length, content-type, date, x-forwarded-for, fspiop-source, | ||
* fspiop-destination, fspiop-encryption,fspiop-signature, fspiop-uri fspiop-http-method | ||
* produces: application/json | ||
* responses: 200, 400, 401, 403, 404, 405, 406, 501, 503 | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const put = async (_context: any, request: Request, h: ResponseToolkit): Promise<ResponseObject> => { | ||
const span = (request as any).span | ||
const transactionRequestId: string = request.params.ID | ||
const payload = request.payload as APIErrorObject | ||
|
||
try { | ||
const tags: { [id: string]: string } = getSpanTags( | ||
request, | ||
Enum.Events.Event.Type.TRANSACTION_REQUEST, | ||
Enum.Events.Event.Action.PUT, | ||
{ transactionRequestId: request.params.transactionRequestId }) | ||
|
||
span?.setTags(tags) | ||
await span?.audit({ | ||
headers: request.headers, | ||
payload: request.payload | ||
}, AuditEventAction.start) | ||
|
||
// Note: calling async function without `await` | ||
Transactions.forwardTransactionRequestError( | ||
request.headers, | ||
Enum.EndPoints.FspEndpointTemplates.TP_TRANSACTION_REQUEST_PUT_ERROR, | ||
Enum.Http.RestMethods.PUT, | ||
transactionRequestId, | ||
payload, | ||
span | ||
) | ||
.catch(err => { | ||
// Do nothing with the error - forwardTransactionRequestError takes care of async errors | ||
Logger.error('Transactions::put - forwardTransactionRequestError async handler threw an unhandled error') | ||
Logger.error(ReformatFSPIOPError(err)) | ||
}) | ||
|
||
return h.response().code(Enum.Http.ReturnCodes.OK.CODE) | ||
} catch (err) { | ||
const fspiopError = ReformatFSPIOPError(err) | ||
Logger.error(fspiopError) | ||
throw fspiopError | ||
} | ||
} | ||
|
||
export default { | ||
put | ||
} |
Oops, something went wrong.