Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Return early on non-Joi errors #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

randyxli
Copy link

Hapi allows defining custom validation functions in the validate route option (see the test in the PR). These functions can throw an error that's not a Joi error, which triggers a type error in Relish:

Debug: internal, implementation, error 
    TypeError: Cannot read property 'map' of undefined
    at Relish.parseError (/Users/randy/src/relish/index.js:17:106)
    at Relish.exports.failAction (/Users/randy/src/relish/index.js:61:105)
    at module.exports.internals.Manager.execute (/Users/randy/src/relish/node_modules/hapi/lib/toolkit.js:35:57)
    at module.exports.internals.Manager.failAction (/Users/randy/src/relish/node_modules/hapi/lib/toolkit.js:99:21)
    at Object.internals.input (/Users/randy/src/relish/node_modules/hapi/lib/validation.js:120:34)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Since Relish is designed to handle Joi errors, this PR proposes to fix the error by early returning when the handled error is not a Joi error.

Separately, to test I installed Boom, which caused huge changes in the package-lock.json. If you have any tips on how to minimize those changes, I'm all ears. Thanks for considering my PR!

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 16a88cc on randyxli:custom-validation into 9d570fa on dialexa:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 16a88cc on randyxli:custom-validation into 9d570fa on dialexa:master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants