actix_sqlx_tx/
error.rs

1use actix_web::{
2    http::{header::ContentType, StatusCode},
3    HttpResponse, ResponseError,
4};
5
6#[derive(Debug, thiserror::Error)]
7pub enum Error {
8    /// Indicates that the [`Layer`](crate::Layer) middleware was not installed.
9    #[error("required extension not registered; did you add the axum_sqlx_tx::Layer middleware?")]
10    MissingExtension,
11
12    /// Indicates that [`Tx`] was extracted multiple times in a single handler/middleware.
13    #[error("axum_sqlx_tx::Tx extractor used multiple times in the same handler/middleware")]
14    OverlappingExtractors,
15
16    /// A database error occurred when starting the transaction.
17    #[error(transparent)]
18    Database {
19        #[from]
20        error: sqlx::Error,
21    },
22}
23
24impl ResponseError for Error {
25    fn error_response(&self) -> HttpResponse {
26        HttpResponse::build(self.status_code())
27            .insert_header(ContentType::html())
28            .body(self.to_string())
29    }
30
31    fn status_code(&self) -> StatusCode {
32        StatusCode::INTERNAL_SERVER_ERROR
33    }
34}