Closed mellowagain closed 2 years ago
The layout and initial code for error handling as well as proc macro generation is now finished.
I will now start porting every single module to use the new error handling. I will create one commit per module. They will end up being squashed when this pull request gets merged.
Everything has been ported. LGTM
GitArena's error handling is currently in a very messy state. This pull request aims to fix this.
die!
. This is meant to replace the oldreturn Err(GAError::Type.into());
pattern that can be seen in almost every route.Error
s to the route as a wholeanyhow!
.?
) to have a custom status code instead of always resulting in an500 Internal server error
. Maybe there should be a helper trait for this.This propsal would transform current routes to look something like this:
In case a error in this route occurs (either throught a propagated error using
?
or a specificly crafted one using thedie!
macro, the error will be displayed as html (err = "html"
) to the end user. The error message will be shown under either of these two specific circumenstances:die!
macro and has a message supplied with it as second argument.map_err
to aGitArenaError
which hasdisplay
set totrue
. Maybe we should also make a trait with an extension method.display()
which makes this more convient to use.If none of these two are met, the generic message will be displayed corresponding to the error's status code. For a 500 error that would be
Internal server error
or for a 401Unauthorized