You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
failAction: detailedError to log, defaultError to response #4040
which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Community, Core
is this issue currently blocking your project? (yes/no): yes
is this issue affecting a production system? (yes/no): no
Context
node version: v12.14.1
module version: 19.0.5
environment (e.g. node, browser, native): node
used with (e.g. hapi application, another framework, standalone, ...): hapi app
any other relevant information: -
What problem are you trying to solve?
It wold be awesome to have failAction to log detailedError to the console, defaultError to the response.
Current implementation allows:
failAction: 'error'// defaultError to log and to response
failAction: (request,h,err)=>{request.log('error',err);throwerr}// detailedError to log and to response
There is no way to access both detailedError and defaultError.
Do you have a new or modified API suggestion to solve the problem?
constserver=Hapi.server({routes: {validate: {failAction: (request,h,err)=>{// log to console detailedErrorrequest.log('validation',err);// send to client just 400throwBoom.badRequest();},},},});
But it is look like a bit hacky. It wold be great to have this behaviour in core: log details and send to the client without details.
@mahnunchik why do you use throw Boom.badRequest()? You should use return Boom.badRequest('Some Message'). And why you said that this is a bit hacky? The Boom is Hapi.js core plugin, just splited for best maintenance.
Activity
hueniverse commentedon Mar 13, 2020
You can just create your own default error. It is just a simple
Boom.badRequest()...mahnunchik commentedon Mar 14, 2020
@hueniverse Hi, you don't understand the problem. It is impossible to create custom error for each
4xxи5xxerrors in hapi core and plugins...hueniverse commentedon Mar 14, 2020
I have no idea what the problem is.
mahnunchik commentedon Mar 16, 2020
@hueniverse There are no simple way to do following:
defaultErrorto the response — this kind of error hides details from the client.detailedErrorto the console — with details to better understand what is happening.There are options to have
defaultErrorORdetailedErrorin both places.hueniverse commentedon Mar 16, 2020
Yes there is. You just don't need
defaultError. You can create one yourself! It is just a simpleBoom.badRequest().mahnunchik commentedon Mar 16, 2020
Yep, I may do the following:
But it is look like a bit hacky. It wold be great to have this behaviour in core: log details and send to the client without details.
AndriiNyzhnyk commentedon Mar 16, 2020
@mahnunchik why do you use
throw Boom.badRequest()? You should usereturn Boom.badRequest('Some Message'). And why you said that this is a bit hacky? The Boom is Hapi.js core plugin, just splited for best maintenance.mahnunchik commentedon Mar 17, 2020
Hi @AndriiNyzhnyk
That is the difference of
throw Boom.badRequest()andreturn Boom.badRequest()in case offailActionhandler?Yep! But we already have:
detailedErrordefaultError- Boom.badRequest with appropriate error messageInvalid request ${source} input.We will loose this message if we use new
Boom.badRequesterror in thefailActionhandler.It is impossible to access
defaultErrorin thefailActionhandler. Look at this two lines: https://github.com/hapijs/hapi/blob/master/lib/validation.js#L148 and https://github.com/hapijs/hapi/blob/master/lib/toolkit.js#L133 onlydetailsexposed tofailAction.