Skip to content

964-CreateHapiPluginToValidateErrorCodesOnPreHandler - #72

Merged
rmothilal merged 13 commits into
mojaloop:masterfrom
gibaros:features/Issue964-ValidateErrorCodes
Oct 1, 2019
Merged

rmothilal merged 13 commits into
mojaloop:masterfrom
gibaros:features/Issue964-ValidateErrorCodes

Conversation

@gibaros

@gibaros gibaros commented Sep 19, 2019 •

Copy link
Copy Markdown
Contributor

Create a hapijs plugin to validate error codes onPreHandler.

NOTE: Currently only used at the ml-api-adapter at PUT /transfers/{id}/error route

@mdebarros mdebarros left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments.

Comment thread src/handler.js Outdated
let incomingErrorCode
if (response instanceof ErrorFactory.FSPIOPError || response.isBoom) {
try {
incomingErrorCode = response.toApiErrorObject.ErrorInformation.errorCode

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary overhead as you can just get the errorCode directly from the error object. Use instead response.apiErrorCode.code (ref: https://github.com/mojaloop/sdk-standard-components/blob/master/src/lib/errors/index.js#L120)

Also, I do not believe that you will be receiving an FSPIOPError here. You are going to be receiving an errorInformation object in the payload. So the above recommendation is not really applicable. You should be instead checking the request.payload.errorInformation.errorCode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with last commit

Comment thread src/handler.js Outdated
// TODO: validateFSPIOPErrorCode throws an exception if code is not valid at which point
// we nee to call response.takeover()
// response.takeover(ErrorFactory.createFSPIOPError(Errors.VALIDATION_ERROR, `The incoming error code: ${incomingErrorCode} is not a valid mojaloop specification error code`))
return reply.response(ErrorFactory.createFSPIOPError(Errors.VALIDATION_ERROR, `The incoming error code: ${incomingErrorCode} is not a valid mojaloop specification error code`)).code(400)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here:

  1. I believe you need to add the .takeover() at the end of the calling stack
  2. You will need to ensure that you toApiErrorObject the error is also called on the FSPIOPError assuming that the prehandler is skipped (which would have done this for you). Please verify if this is required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with last commit

Comment thread src/handler.js Outdated
// TODO: validateFSPIOPErrorCode throws an exception if code is not valid at which point
// we nee to call response.takeover()
// response.takeover(ErrorFactory.createFSPIOPError(Errors.VALIDATION_ERROR, `The incoming error code: ${incomingErrorCode} is not a valid mojaloop specification error code`))
return reply.response(ErrorFactory.createFSPIOPError(Errors.VALIDATION_ERROR, `The incoming error code: ${incomingErrorCode} is not a valid mojaloop specification error code`)).code(400)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Point 2 above applies here as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed with last commit

-add takeover() to onPreHandler plugin response
-add toApiErrorObject()
-instead of obtaining the response from the request object, obtain the payload and specifically its error code
-change boolean if validateFspiopErrorCode to null check

@rmothilal rmothilal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please rename to appropriate name

Comment thread src/handler.js Outdated
* @param h
* @returns {boolean|h.continue|continue|((key?: IDBValidKey) => void)}
*/
exports.onPreHandler = function (request, h) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename function to more appropriate name

-let code execution continue if valid mojaloop error code received
-add dependency check and update scripts
-add unit tests to cover onPreHandler function
-add unit test to meet code coverage requirement
-update unit test to cover 2 invalid error codes, for invalid category and invalid specific error
-add .ncurc.yml
-add prune run command
-remove istanbul
-run update dep check
-rename pretest to standard

@rmothilal rmothilal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thumbs up

@rmothilal
rmothilal merged commit 767d49c into mojaloop:master Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants