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

Route not found #7

Open
NikosPg opened this issue Jun 22, 2023 · 2 comments
Open

Route not found #7

NikosPg opened this issue Jun 22, 2023 · 2 comments

Comments

@NikosPg
Copy link

NikosPg commented Jun 22, 2023

my server when i run it says Route not found
Jun 22 21:23:07.849 INFO return_error{r=Rejection([MethodNotAllowed, MethodNotAllowed, MethodNotAllowed, MethodNotAllowed, MethodNotAllowed, MethodNotAllowed])}: handle_errors: close time.busy=199µs time.idle=19.8µs

What am i doing wrong?!

@charlielu05
Copy link

I'm getting the same issue at the end of chapter 9. Did you ever find a resolution to this @NikosPg ?

@charlielu05
Copy link

Answering my own question here but I found that the issue was because my verify_token function was failing due to a silly spelling mistake on my token's claim "account_id" key but the error match case in the auth method was not propagating the returned handle_errors::Error::CannotDecryptToken

pub fn auth(
) -> impl Filter<Extract = (Session,), Error = warp::Rejection> + Clone {
    warp::header::<String>("Authorization").and_then(|token: String| {
        let token = match verify_token(token) {
            Ok(t) => t,
            Err(_) => return future::ready(Err(warp::reject::reject())),
        };

        future::ready(Ok(token))
    })
}

This in turn resulted in the handle-errors not able to match with any of the defined errors which meant it returned with the:

else {
        event!(Level::WARN, "Requested route was not found");
        Ok(warp::reply::with_status(
            "Route not found".to_string(),
            StatusCode::NOT_FOUND,
        ))
    }

I was able to find this issue by setting a mock response for the POST questions route that just echos the JSON payload from the client/user and observing that this worked when I removed the authentication step from the route.
I then added two separate kinds of errors for my verify_token function to see where the error was happening:

pub fn verify_token(
    token: String,
) -> Result<Session, handle_errors::Error> {
    dbg!(&token);

    let decrypted_token = paseto::tokens::validate_local_token(
        &token,
        None,
        &"RANDOM WORDS WINTER MACINTOSH PC".as_bytes(),
        &paseto::tokens::TimeBackend::Chrono,
    )
    .map_err(|_| handle_errors::Error::CannotDecryptToken)?;

    dbg!(&decrypted_token);
    serde_json::from_value::<Session>(decrypted_token)
        .map_err(|_| handle_errors::Error::CannotConstructSession)
}

I was finally then able to see the spelling mistake I did on my account_id key for my token.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants