Skip to content
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

Badly implemented Boom like class can cause runtime error #305

Open
matthieusieben opened this issue Dec 7, 2023 · 1 comment
Open

Badly implemented Boom like class can cause runtime error #305

matthieusieben opened this issue Dec 7, 2023 · 1 comment
Labels
bug Bug or defect

Comments

@matthieusieben
Copy link

matthieusieben commented Dec 7, 2023

Runtime

na

Runtime version

na

Module version

all

Last module version without issue

?

Used with

standalone

Any other relevant information

No response

What are you trying to achieve or the steps to reproduce?

const BadBoom = class extends Error { isBoom = true; };
Boom.isBoom(new BadBoom()); // true
Boom.isBoom(new BadBoom(), 404); // Cannot read properties of undefined (reading 'statusCode')

What was the result you got?

An error because err.output is undefined in the BadBoom instance

What result did you expect?

I know that isBoom is meant to work with object created only with any version of the @hapi/boom package but it could at least ensure that err.output is an object and that err.output.statusCode is a number.

What do you think ?

@matthieusieben matthieusieben added the bug Bug or defect label Dec 7, 2023
@kanongil
Copy link
Contributor

kanongil commented Dec 7, 2023

I agree in principle, but in practice this won't ever matter.

Anyway, given a fix can be a single added ?, I won't mind it being added:

return err instanceof Error && !!err.isBoom && (!statusCode || err.output?.statusCode === statusCode);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants