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

Added typeOf functionality #156

merged 3 commits into from May 28, 2017


Copy link

blackdynamo commented May 26, 2017

Hey guys,

This may be a special use case, but it makes for nice filtering of errors without having to deep check vs strings and numbers.

Although it doesn't satisfy the instanceof concern as seen here #101, it does make filtering manually cleaner.

Instead of having to do such things as:

import boom from "boom";

const err = boom.notFound("Something is not found");
if (err.isBoom && err.output.statusCode === 404) return; // true;
if (err.isBoom && err.output.payload.statusCode === 404) return; // true;
if (err.isBoom && err.output.payload.error === "Not Found") return; // true;

You can instead do:

import boom from "boom";

const err = boom.notFound("Something is not found");
if (err.isBoom && err.typeOf(boom.notFound)) return; // true;

This keeps the logic simpler and also prevents potential spelling errors, remembering status codes, and internal changes to the structure of the output.


This comment has been minimized.

Copy link

hueniverse commented May 27, 2017

Not crazy about the format. Maybe assign typeof as a property of the error and then you do err.typeof === Boom.notFound.

@hueniverse hueniverse added the feature label May 28, 2017
@hueniverse hueniverse added this to the 5.0.1 milestone May 28, 2017
@hueniverse hueniverse self-assigned this May 28, 2017
@hueniverse hueniverse merged commit 898a364 into hapijs:master May 28, 2017
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
hueniverse added a commit that referenced this pull request May 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.