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

Easy way to determine if the client or server is at fault #41

Closed
maxedmands opened this issue Dec 12, 2014 · 9 comments · Fixed by #45
Assignees
Labels
Milestone

Comments

@maxedmands
Copy link

@maxedmands maxedmands commented Dec 12, 2014

Wouldn't it be great if you could do:

error = Boom.notFound()
error.isClient // => true

error = Boom.notImplemented()
error.isClient // => false

What do you think?

Alternative approach:

error = Boom.notFound()
Boom.isClient(error) // => true

error = Boom.notImplemented()
Boom.isClient(error) // => false
@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Dec 13, 2014

I'm not sure how you would be able to programmatically determine that? You if you, the developer know which end caused the problem, you'd have to set it anyway. I mean status codes can be used in a variety of contexts; 404 doesn't always imply sever error.

@maxedmands

This comment has been minimized.

Copy link
Author

@maxedmands maxedmands commented Dec 15, 2014

I am operating under the assumption that 4xx errors are all "client" errors, and 5xx errors are all "server" errors. (See the HTTP/1.1 spec, it seems to corroborate this...)

@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Dec 15, 2014

What is the use case for this?

While I understand what you're saying about the difference between 400 and 500 errors, that could get into a sort of gray area - if you request a page that doesn't exist (404) whose fault is it really? Is it because an HTML file couldn't be found on disk? Is it because the requestor requested something that doesn't exist? In the former, that would be a server error, the latter a client request. How would you be able to programmatically determine that?

@maxedmands

This comment has been minimized.

Copy link
Author

@maxedmands maxedmands commented Dec 16, 2014

I've implemented a Boom-compatible error middleware for express.

I know, we're not using Hapi, don't ask :|

I'd like to implement another express middleware to log errors, but only if the error has a 5xx status. (It would be really unfortunate and noisy if we got a log message every time someone tried to request a resource that didn't exist -- on the other hand, we definitely want to log a stack trace.)

More from the HTTP/1.1 spec about client vs. server errors:

10.4 Client Error 4xx
   The 4xx class of status code is intended for cases in which the
   client seems to have erred.

10.5 Server Error 5xx
   Response status codes beginning with the digit "5" indicate cases in
   which the server is aware that it has erred or is incapable of
   performing the request.

Totally willing to chat about where the fault might really lie for a 404, but if you have a preferred other way to discern between 4xx and 5xx errors, let's just go with that.

@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Dec 16, 2014

You could just check if (error.statusCode >= 500) then it's a server error in this case.

@maxedmands

This comment has been minimized.

Copy link
Author

@maxedmands maxedmands commented Dec 16, 2014

Yep, that's what I'm doing now. Just thought this would be a nice feature to add is all. Keeps the error code logic inside the HTTP error abstraction.

@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Dec 16, 2014

I'll take a PR for this feature.

@maxedmands

This comment has been minimized.

Copy link
Author

@maxedmands maxedmands commented Dec 16, 2014

Yay, I'll write one then!

@arb arb added the new contributor label Dec 31, 2014
@arb arb modified the milestone: 2.7.0 Jan 5, 2015
arb added a commit to arb/boom that referenced this issue Jan 5, 2015
@arb arb mentioned this issue Jan 5, 2015
@maxedmands

This comment has been minimized.

Copy link
Author

@maxedmands maxedmands commented Jan 5, 2015

Sorry for leaving this languishing; thanks for the feature! 😄

@hueniverse hueniverse added feature and removed request labels Sep 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.