Skip to content
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

Fix catch_panic_return_internal_server_error_response test #1464

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions fastn-core/src/catch_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
///
/// ```
/// # use actix_web::App;
/// use actix_web_lab::middleware::CatchPanic;

Check failure on line 28 in fastn-core/src/catch_panic.rs

View workflow job for this annotation

GitHub Actions / Rust Checks

failed to resolve: use of undeclared crate or module `actix_web_lab`
///
/// App::new().wrap(CatchPanic::default())
/// # ;
Expand All @@ -34,7 +34,7 @@
/// ```no_run
/// # use actix_web::App;
/// use actix_web::middleware::{Logger, NormalizePath};
/// use actix_web_lab::middleware::CatchPanic;

Check failure on line 37 in fastn-core/src/catch_panic.rs

View workflow job for this annotation

GitHub Actions / Rust Checks

failed to resolve: use of undeclared crate or module `actix_web_lab`
///
/// // recommended wrap order
/// App::new()
Expand Down Expand Up @@ -84,12 +84,16 @@
.map(move |res| match res {
Ok(Ok(res)) => Ok(res),
Ok(Err(svc_err)) => Err(svc_err),
Err(_panic_err) => Err(error::ErrorInternalServerError("500 Server Error")),
Err(_panic_err) => Err(error::ErrorInternalServerError(
INTERNAL_SERVER_ERROR_MESSAGE,
)),
})
.boxed_local()
}
}

const INTERNAL_SERVER_ERROR_MESSAGE: &str = "500 Server Error";

#[cfg(test)]
mod tests {
use actix_web::{
Expand Down Expand Up @@ -146,6 +150,6 @@
let res = err.error_response();
assert_eq!(res.status(), StatusCode::INTERNAL_SERVER_ERROR);
let body = to_bytes(res.into_body()).await.unwrap();
assert!(body.is_empty());
assert_eq!(body, INTERNAL_SERVER_ERROR_MESSAGE)
}
}
Loading