error.code() and error handling
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(),
)),
}
}
Hi. The error code depends on the code that is returned by the server. Can you share some of your server code here?
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")),
}
}
Hi. This is already tested in the test cases: https://github.com/devashishdxt/tonic-web-wasm-client/blob/c89a136c1095c5a242334879cb3fdb32965ca04c/test-suite/simple/client/tests/web.rs#L79
I cannot suggest any meaningful solution for this unless I have a failing test full code which does not behave correctly.
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?
Yes @cyanic-selkie
I opened an issue on the tonic repository.
Closing this issue
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_webcrate.I'm guessing this is an issue with
tonic_webthen. @npcnuno, is your server using that crate as well?
I have the same issue when I use tonic gprc server behind the nginx proxy