-
Notifications
You must be signed in to change notification settings - Fork 293
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
Improve top-level error handling #526
Comments
I'd just like to throw in my 5 cents while you're considering error handling. With the new axum support, the lack of implementation of I currently have this newtype wrapper to work around and preserve the ergonomics of the pub struct ErrWrapper(worker::Error);
impl From<worker::Error> for ErrWrapper {
fn from(value: worker::Error) -> Self {
ErrWrapper(value)
}
}
impl IntoResponse for ErrWrapper {
fn into_response(self) -> axum::response::Response {
(StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response()
}
}
pub type Result<T> = StdResult<T, ErrWrapper>;
#[axum::debug_handler]
#[worker::send]
async fn create_game(
State(env): State<Env>,
req: Request<axum::body::Body>,
) -> Result<worker::HttpResponse> {
let game_code = generate_game_code();
Ok(env
.durable_object("GAME")?
.id_from_name(game_code.deref())?
.get_stub()?
.fetch_with_request(req.try_into()?)
.await?
.try_into()?)
} The examples in the repo just unwrap the error which panics, however if I understand correctly However when trying to use APIs like the Durable Object API inside an axum handler, if you'd like middleware or other tower service's to work with the Although perhaps there isn't a canonical implementation of |
Can't it just take a |
Yes, I believe the current consensus is that the return type is something like that where |
Is there an existing issue for this?
Description
Should we just accept
anyhow::Error
or something else generic?The text was updated successfully, but these errors were encountered: