-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Add not found schema to base services #2632
Comments
Something I've seen (which I think is along the very same lines), is that for not found scenarios some services will return an HTTP 200 with an html page (that contains the text '404 Not Found'). Would it be feasible to have a |
😝 Are these JSON services? |
Two places where I've seen this recently are:
😆 They'll return JSON if the query target exists, but doing that HTML nonsense otherwise. I believe the current behavior with those would be |
It'd be nice to improve on that. |
Actually I'm wrong 🤦♂️ Forgot I added this to return a more meaningful message. Still would be great if those services would actually respond with a 404 status code or always return JSON so we could use the |
This code is from the clojar badge:
We have a bunch of other similar examples, where the schema is written to accommodate the not found case, and then there's code written to detect the alternate case and throw an error.
This responsibility is a kind of schema validation. We'd have clearer guarantees, particularly in the "found" case, if this responsiblity were delegated to Joi.
A really clean way to express this would be to optionally provide two schemas to
_requestJson
and friends. One would be theschema
for the success case (like what we're passing now) and the other anotFoundSchema
. If thenotFoundSchema
matches, we automatically throwNotFound
, using the 404 error message.The text was updated successfully, but these errors were encountered: