Skip to content

Commit

Permalink
add error logging for /verify endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill-K-1 committed Jan 18, 2024
1 parent 5cb15d9 commit bdc569a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
5 changes: 4 additions & 1 deletion user-verifier/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub enum AppError {
SigningError(#[from] k256::ecdsa::Error),
#[error("Http request failed: {0}")]
ReqwestError(#[from] reqwest::Error),
#[error("Fractal error: {0}")]
FractalError(String),
}

impl IntoResponse for AppError {
Expand All @@ -29,7 +31,8 @@ impl IntoResponse for AppError {
Self::ParseError(_)
| Self::ServerError(_)
| Self::SigningError(_)
| Self::ReqwestError(_) => (
| Self::ReqwestError(_)
| Self::FractalError(_) => (
StatusCode::INTERNAL_SERVER_ERROR,
"Internal server error".to_owned(),
),
Expand Down
14 changes: 7 additions & 7 deletions user-verifier/src/fractal/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl FractalClient {
oauth_token = self.refresh_oauth_token(oauth_token).await?;
}

tracing::trace!("Acquired user token: {oauth_token:?}");
tracing::debug!("Acquired user token: {oauth_token:?}");

let fetched_res = self
.inner_client
Expand Down Expand Up @@ -96,10 +96,10 @@ impl FractalClient {
token: oauth_token,
})
}
Err(e) => {
tracing::error!("Unable to fetch user. Error: {:?}", e);
Err(e)
}
Err(e) => Err(AppError::FractalError(format!(
"Unable to fetch user. Error: {:?}",
e
))),
}
}

Expand All @@ -125,7 +125,7 @@ impl FractalClient {
.text()
.await?;

tracing::trace!("Acquired raw fractal token response: {data}");
tracing::debug!("Acquired raw fractal token response: {data}");

match serde_json::from_str::<TokenDetails>(&data) {
Ok(token) if token.token_type.as_str() == "Bearer" => Ok(OAuthToken::from(token)),
Expand All @@ -135,7 +135,7 @@ impl FractalClient {
}

async fn refresh_oauth_token(&self, oauth_token: OAuthToken) -> Result<OAuthToken, AppError> {
tracing::trace!("Refresh for OAuthToken: {oauth_token:?}");
tracing::debug!("Refresh for OAuthToken: {oauth_token:?}");

let params: [(&str, &str); 4] = [
("client_id", &self.config.client_id),
Expand Down
16 changes: 12 additions & 4 deletions user-verifier/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,20 @@ async fn verify_endpoint(
) -> Result<Json<VerifyAccountResponse>, AppError> {
tracing::debug!("Request: {req:?}");

let user = state
let result = match state
.client
.fetch_and_verify_user(req.token, req.wallet)
.await?;

let result = create_verify_account_response(&state.signer, req.wallet, user, Utc::now());
.await
{
Ok(user) => create_verify_account_response(&state.signer, req.wallet, user, Utc::now()),
Err(e) => {
tracing::warn!(
"Failed to process verify request (wallet: {}). Error: {e}",
req.wallet
);
return Err(e);
}
};

tracing::debug!("Response: {result:?}");

Expand Down

0 comments on commit bdc569a

Please sign in to comment.