Enum axum_sqlx_tx::Error
source · pub enum Error {
MissingExtension,
OverlappingExtractors,
Database {
error: Error,
},
}
Expand description
Possible errors when extracting Tx
from a request.
axum
requires that the FromRequest
Rejection
implements IntoResponse
, which this does
by returning the Display
representation of the variant. Note that this means returning
configuration and database errors to clients, but you can override the type of error that
Tx::from_request
returns using the E
generic parameter:
use axum::response::IntoResponse;
use axum_sqlx_tx::Tx;
use sqlx::Sqlite;
struct MyError(axum_sqlx_tx::Error);
// The error type must implement From<axum_sqlx_tx::Error>
impl From<axum_sqlx_tx::Error> for MyError {
fn from(error: axum_sqlx_tx::Error) -> Self {
Self(error)
}
}
// The error type must implement IntoResponse
impl IntoResponse for MyError {
fn into_response(self) -> axum::response::Response {
(http::StatusCode::INTERNAL_SERVER_ERROR, "internal server error").into_response()
}
}
async fn handler(tx: Tx<Sqlite, MyError>) {
/* ... */
}
Variants§
MissingExtension
Indicates that the Layer
middleware was not installed.
OverlappingExtractors
Indicates that Tx
was extracted multiple times in a single handler/middleware.
Database
Fields
§
error: Error
A database error occurred when starting the transaction.
Trait Implementations§
source§impl Error for Error
impl Error for Error
source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
source§impl IntoResponse for Error
impl IntoResponse for Error
source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.