error-stack: How to give a "reason" to an error? #2089
Unanswered
kee-oth
asked this question in
Help (Libraries)
Replies: 1 comment
-
Hi @kee-oth and sorry for not responding this long, I must have missed this question. I see multiple ways to achieve this. Either way would work and it's up to your application which is the best design, use whatever works best for you.
It's correct, that you cannot search for a specific enum variant by using Hope, this helped you 🙂 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to integrate error-stack into an API/web service project built with Axum. I wondering about the best way to handle differentiating "reasons" for an error.
So the specific situation I'm facing:
I'm using a 3rd party auth service to handle my authentication. This requires me sending http requests to their service. I want my route handler to know if a call received a
400 BAD_REQUEST
from the auth service and pass that information along as information in the handler's response. Otherwise, I just want to say it's a500 INTERNAL_SERVER_ERROR
.The flow looks like this:
Handler --> Internal Auth Service --> External Auth Service --> Internal Auth Service --> Handler
So there's a layer of abstraction between the Handler and the External Auth Service that blocks the handler from directly knowing if External Auth Service produces a
400
error vs any other error. What's the recommended way of passing along that information? I figure I need an "Error" and a "reason" for that Error. Then I need to access the reason and determine which reason it is.What's the best way to handle this? I thought about
attach
ing something and usingcontains
butcontains
doesn't work with my current enum/variant setup for failure reasons. I could refactor and break out each enum variant into its own struct but that feels clunky.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions