-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor/improve error handling #48
Changes from all commits
84328a0
6230fdc
f657262
703ee66
96d119f
6571bd6
b203824
cf28151
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
allow-unwrap-in-tests = true | ||
allow-expect-in-tests = true | ||
Comment on lines
+1
to
+2
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still allow |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,13 +68,15 @@ struct CreateCalendarUseCase { | |
|
||
#[derive(Debug)] | ||
enum UseCaseError { | ||
InternalError, | ||
UserNotFound, | ||
StorageError, | ||
} | ||
|
||
impl From<UseCaseError> for NettuError { | ||
fn from(e: UseCaseError) -> Self { | ||
match e { | ||
UseCaseError::InternalError => Self::InternalError, | ||
UseCaseError::StorageError => Self::InternalError, | ||
UseCaseError::UserNotFound => { | ||
Self::NotFound("The requested user was not found.".to_string()) | ||
|
@@ -92,7 +94,14 @@ impl UseCase for CreateCalendarUseCase { | |
const NAME: &'static str = "CreateCalendar"; | ||
|
||
async fn execute(&mut self, ctx: &NettuContext) -> Result<Self::Response, Self::Error> { | ||
let user = match ctx.repos.users.find(&self.user_id).await { | ||
let user = ctx | ||
.repos | ||
.users | ||
.find(&self.user_id) | ||
.await | ||
.map_err(|_| UseCaseError::InternalError)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this It allows to return directly the error. This is equivalent to the following let user = match ctx
.repos
.users
.find(&self.user_id)
.await
.map_err(|_| UseCaseError::InternalError) {
Ok(user) => user,
Err(e) => return Err(e), // Early return in the function
}; |
||
|
||
let user = match user { | ||
Some(user) if user.account_id == self.account_id => user, | ||
_ => return Err(UseCaseError::UserNotFound), | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the name suggests, it allows to autoreload the app in dev when the source code changes