Skip to content

Commit

Permalink
feat: not_found error status handled
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-hagemann committed Dec 6, 2023
1 parent b76bcaf commit 3952941
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/features/chart/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub enum ChartError {
FailedToGetChart,
#[error("unknown chart error")]
Unknown,
#[error("could not find data for given timeframe")]
NotFound,
}
2 changes: 1 addition & 1 deletion src/features/chart/infrastructure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(crate) async fn get_votes_summary_by_timeframe(
.await
.map_err(|error| {
error!("{error:?}");
ChartError::Unknown
ChartError::NotFound
})?;

Ok(result)
Expand Down
8 changes: 7 additions & 1 deletion src/features/chart/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use tonic::{Request, Response, Status};

use crate::features::pb::chart::chart_server::Chart;

use super::errors::ChartError;
use super::{service::ChartService, use_cases};

#[tonic::async_trait]
Expand Down Expand Up @@ -41,7 +42,12 @@ impl Chart for ChartService {
};
Ok(Response::new(payload))
}
Err(_error) => Err(Status::unknown("Internal server error")),
Err(error) => match error {
ChartError::NotFound => {
Err(Status::not_found("Cannot find data for given timeframe."))
}
_ => Err(Status::unknown("Internal server error")),
},
}
}
}

0 comments on commit 3952941

Please sign in to comment.