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

error.code() and error handling #57

Closed
npcnuno opened this issue Feb 15, 2024 · 8 comments
Closed

error.code() and error handling #57

npcnuno opened this issue Feb 15, 2024 · 8 comments

Comments

@npcnuno
Copy link

npcnuno commented Feb 15, 2024

I can't get the error code from the backend, making error handling difficult on the client

I always get code = "Unknow error" when I try to get the error code from the backend

#[wasm_bindgen]
pub async fn refresh_token(refresh: String) -> Result<JsValue, JsValue> {
let mut client = AuthenticationClient::new(build_client());
let result = client
.refresh_token_admin(RefreshRequest {
refresh_token: refresh,
})
.await;

match result {
    Ok(response) => {
        let res = response.into_inner();
        Ok(JsValue::from_str(
            &serde_json::json!({
            "code" : "0",
            "description": res.auth_token.to_string()})
            .to_string(),
        ))
    }
    Err(error) => Err(JsValue::from_str(
        &serde_json::json!({
            "code": error.code().to_string(),
            "description": error.details(),
        })
        .to_string(),
    )),
}

}

@devashishdxt
Copy link
Owner

Hi. The error code depends on the code that is returned by the server. Can you share some of your server code here?

@npcnuno
Copy link
Author

npcnuno commented Mar 11, 2024

let admin: Option<Admin> = match admin.unwrap().take(0) {
    Ok(a) => a,
    Err(_) => return Err(Status::internal("couldn't query db")),
};
if admin.is_none() {
    return Err(Status::internal("couldn't query db"));
}
let admin = admin.unwrap();
match create_jwt_auth(
    &decoded.uid,
    &admin.institution.id.to_string(),
    Previlege::from_str(&head.typ.unwrap()).unwrap(),
) {
    Ok(a) => Ok(Response::new(RefreshResponse { auth_token: a })),
    Err(_) => Err(Status::internal("couldn't create auth from refresh")),
}

}

@devashishdxt
Copy link
Owner

Hi. This is already tested in the test cases:

async fn test_error_response() {

I cannot suggest any meaningful solution for this unless I have a failing test full code which does not behave correctly.

@cyanic-selkie
Copy link

cyanic-selkie commented Mar 26, 2024

Hi, I'm having the same issue. However, I only started encountering the issue once I swapped the traefik reverse proxy that handled grpc-web translation with the tonic_web crate.

I'm guessing this is an issue with tonic_web then. @npcnuno, is your server using that crate as well?

@npcnuno
Copy link
Author

npcnuno commented Mar 26, 2024

Yes @cyanic-selkie

@cyanic-selkie
Copy link

I opened an issue on the tonic repository.

@devashishdxt
Copy link
Owner

Closing this issue

@imotai
Copy link

imotai commented Aug 7, 2024

Hi, I'm having the same issue. However, I only started encountering the issue once I swapped the traefik reverse proxy that handled grpc-web translation with the tonic_web crate.

I'm guessing this is an issue with tonic_web then. @npcnuno, is your server using that crate as well?

I have the same issue when I use tonic gprc server behind the nginx proxy

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

4 participants