mellowagain / gitarena

Software development platform with built-in vcs, issue tracking and code review
MIT License
82 stars 10 forks source link

Revamp error handling #29

Closed mellowagain closed 2 years ago

mellowagain commented 2 years ago

GitArena's error handling is currently in a very messy state. This pull request aims to fix this.

This propsal would transform current routes to look something like this:

#[route("/login", method = "GET", err = "html")]
pub(crate) async fn get_login(web_user: WebUser, db_pool: web::Data<PgPool>) -> Result<impl Responder> {
    if matches!(web_user, WebUser::Authenticated(_)) {
        die!(UNAUTHORIZED, "Already logged in");
    }

    ...
}

In case a error in this route occurs (either throught a propagated error using ? or a specificly crafted one using the die! 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:

  1. The error has been caused by the die! macro and has a message supplied with it as second argument
  2. The propagated error was .map_err to a GitArenaError which has display set to true. 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 401 Unauthorized

mellowagain commented 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.

mellowagain commented 2 years ago

Everything has been ported. LGTM