Skip to content

How to implement uniform custom error? #280

Discussion options

You must be logged in to vote

I found my errors :

  1. ErrorMiddleware should before Cors:
let app = Route::new()
        .nest("/api", api)
        .nest("/", ui)
        .with(middleware::ErrorMiddleware)
        .with(Cors::new())
        .data(pool);
#[poem::async_trait]
impl<E: Endpoint> Endpoint for ErrorMiddlewareImpl<E> {
    type Output = Response;

    async fn call(&self, req: Request) -> Result<Self::Output> {
        let method = req.method().clone();
        let uri = req.uri().clone();
        let start = Instant::now();
        let resp = self.ep.call(req).await;
        let elapsed = start.elapsed();
        match resp {
            Ok(resp) => {
                let resp = resp.into_response();

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
6 replies
@Christoph-AK
Comment options

@jonathanblade
Comment options

@jonathanblade
Comment options

@Christoph-AK
Comment options

@jonathanblade
Comment options

Comment options

You must be logged in to vote
1 reply
@sunli829
Comment options

Answer selected by jonathanblade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants