How to return either success or errors? #2210
Unanswered
tobymurray
asked this question in
Questions
Replies: 1 comment 1 reply
-
Edit: There was a bunch of confusing code here that muddied the waters more than helping anything, removed because I don't think it's useful. Didn't delete because @myz-dev has a useful reply that I don't want to orphan |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm just not getting this - it seems like I'm missing something obvious. I want to return either a successful
rocket_dyn_templates::Template
or an error (e.g. 401, 403, 500), and the slight twist is I want to add a custom header as well.First:
What does this mean in practice? What's the response signature for this method?
If I declare e.g.
Result<Template, String>
and returnErr("This is an error".to_string()
, I get an HTTP 200 response with this content. The docs read as though I should expect Rocket to be doing something with theErr
that I'm returning (maybe a 500 or some other default?). Does the default error handler catch errors and turn them into HTTP 200s?Elsewhere the docs suggest:
But this is just the error. Is this example showing how to implement an API (
Responder
) that exclusively returns errors? If so... that's a very confusing piece of documentation, as it seems unlikely anyone would practically use that.I've seen the error handling example, #71, #72, #2155, and #2172 and for the life of me I can't put the pieces together.
Beta Was this translation helpful? Give feedback.
All reactions