Skip to content

Commit

Permalink
improve tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
kentSarmiento committed Dec 26, 2023
1 parent bd45837 commit 5cbcc4a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 36 deletions.
24 changes: 16 additions & 8 deletions link-for-later/src/controller/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,43 @@ impl IntoResponse for AppError {
fn into_response(self) -> Response {
let (status, error_message) = match self {
Self::ServerError(ref e) => {
tracing::debug!("Server error: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::INTERNAL_SERVER_ERROR, self.to_string())
}
Self::DatabaseError(ref e) => {
tracing::debug!("Database error: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::INTERNAL_SERVER_ERROR, self.to_string())
}
Self::LinkNotFound(ref e) => {
tracing::debug!("Link not found: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::NOT_FOUND, self.to_string())
}
Self::UserAlreadyExists(ref e) => {
tracing::debug!("User already exists: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::BAD_REQUEST, self.to_string())
}
Self::UserNotFound(ref e) => {
tracing::debug!("User not found: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::BAD_REQUEST, self.to_string())
}
Self::IncorrectPassword(ref e) => {
tracing::debug!("Incorrect password: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::UNAUTHORIZED, self.to_string())
}
Self::AuthorizationError(ref e) => {
tracing::debug!("Authorization error: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::UNAUTHORIZED, self.to_string())
}
Self::ValidationError(ref e) => {
tracing::debug!("Payload validation error: {}", e.to_string());
tracing::info!("{}", self.to_string());
tracing::debug!("{}: {}", self.to_string(), e.to_string());
(StatusCode::BAD_REQUEST, self.to_string())
}

Expand Down
25 changes: 5 additions & 20 deletions link-for-later/src/controller/links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ async fn list(State(app_state): State<AppState>, user: Claims) -> impl IntoRespo
.await
{
Ok(list) => Json(list).into_response(),
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand Down Expand Up @@ -69,10 +66,7 @@ async fn post(
.await
{
Ok(link) => (StatusCode::CREATED, Json(link)).into_response(),
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand All @@ -88,10 +82,7 @@ async fn get(
.await
{
Ok(link) => Json(link).into_response(),
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand Down Expand Up @@ -120,10 +111,7 @@ async fn put(
.await
{
Ok(link) => Json(link).into_response(),
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand All @@ -139,10 +127,7 @@ async fn delete(
.await
{
Ok(()) => StatusCode::NO_CONTENT.into_response(),
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand Down
10 changes: 2 additions & 8 deletions link-for-later/src/controller/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ async fn register(
.await
{
Ok(_) => StatusCode::CREATED.into_response(),
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand All @@ -72,10 +69,7 @@ async fn login(
let response = AuthResponse::new(token.jwt());
(StatusCode::OK, Json(response)).into_response()
}
Err(e) => {
tracing::error!("Error: {}", e);
e.into_response()
}
Err(e) => e.into_response(),
}
}

Expand Down

0 comments on commit 5cbcc4a

Please sign in to comment.