Axum rust function is not satisfied error

101 Views Asked by At
async fn add_player_to_session(
    Extension(pool): Extension<sqlx::PgPool>,
    Json(session): Json<Session>
) -> Result<StatusCode, sqlx::Error>  {
    sqlx::query!(
        "UPDATE session SET player2 = $1 WHERE id = $2",
        session.player2,
        session.id
    )
    .execute(&pool)
    .await?;

    Ok(StatusCode::OK)
}
error[E0277]: the trait bound `fn(Extension<Pool<Postgres>>, axum::Json<Session>) -> impl Future<Output = Result<axum::http::StatusCode, sqlx::Error>> {add_player_to_session}: Handler<_, _>` is not satisfied
   --> src/main.rs:185:34
    |
185 |         .route("/addplayer", put(add_player_to_session))
    |                              --- ^^^^^^^^^^^^^^^^^^^^^ the trait Handler<_, _> is not implemented for fn item fn(Extension<Pool<Postgres>>, axum::Json<Session>) -> impl Future<Output = Result<axum::http::StatusCode, sqlx::Error>> {add_player_to_session}

can any one help me?

I tried multiple things a solution would be to return a json object but I just want to return a status code

after adding #[debug_handler] i got a more specific error

  --> src/main.rs:119:6
    |
119 | ) -> Result<StatusCode, Error>  {
    |      ^^^^^^ the trait `IntoResponse` is not implemented for `axum::Error`
    |
    = help: the following other types implement trait `IntoResponse`:
              axum::body::Empty<axum::body::Bytes>
              http_body::combinators::box_body::BoxBody<axum::body::Bytes, E>
              http_body::combinators::box_body::UnsyncBoxBody<axum::body::Bytes, E>
              axum::extract::rejection::BodyAlreadyExtracted
              axum::extract::rejection::FailedToBufferBody
              axum::body::Bytes
              axum::extract::rejection::LengthLimitError
              axum::extract::rejection::UnknownBodyError
            and 121 others
    = note: required for `Result<axum::http::StatusCode, axum::Error>` to implement `IntoResponse`
note: required by a bound in `__axum_macros_check_add_player_to_session_into_response::{closure#0}::check`
   --> src/main.rs:119:6
    |
119 | ) -> Result<StatusCode, Error>  {
    |      ^^^^^^ required by this bound in `check`

error[E0277]: the trait bound `fn(Extension<Pool<Postgres>>, axum::Json<Session>) -> impl Future<Output = Result<axum::http::StatusCode, axum::Error>> {add_player_to_session}: Handler<_, _>` is not satisfied
   --> src/main.rs:188:34
    |
188 |         .route("/addplayer", put(add_player_to_session))
    |                              --- ^^^^^^^^^^^^^^^^^^^^^ the trait `Handler<_, _>` is not implemented for fn item `fn(Extension<Pool<Postgres>>, axum::Json<Session>) -> impl Future<Output = Result<axum::http::StatusCode, axum::Error>> {add_player_to_session}`
    |                              |
    |                              required by a bound introduced by this call
    |
    = help: the trait `Handler<T, ReqBody>` is impl

this is the current error that i am facing not sure how to fix it

0

There are 0 best solutions below