Let error handler handle all error logic, logging, and canceling.

This commit is contained in:
mikestefanello 2022-05-17 08:45:18 -04:00
parent cd1887124e
commit acebcf0ba0
10 changed files with 43 additions and 49 deletions

View file

@ -1,6 +1,7 @@
package middleware
import (
"fmt"
"net/http"
"strconv"
@ -25,10 +26,10 @@ func LoadAuthenticatedUser(authClient *services.AuthClient) echo.MiddlewareFunc
c.Set(context.AuthenticatedUserKey, u)
c.Logger().Infof("auth user loaded in to context: %d", u.ID)
default:
if context.IsCanceledError(err) {
return nil
}
c.Logger().Errorf("error querying for authenticated user: %v", err)
return echo.NewHTTPError(
http.StatusInternalServerError,
fmt.Sprintf("error querying for authenticated user: %v", err),
)
}
return next(c)
@ -71,11 +72,10 @@ func LoadValidPasswordToken(authClient *services.AuthClient) echo.MiddlewareFunc
msg.Warning(c, "The link is either invalid or has expired. Please request a new one.")
return c.Redirect(http.StatusFound, c.Echo().Reverse("forgot_password"))
default:
if context.IsCanceledError(err) {
return nil
}
c.Logger().Error(err)
return echo.NewHTTPError(http.StatusInternalServerError)
return echo.NewHTTPError(
http.StatusInternalServerError,
fmt.Sprintf("error loading password token: %v", err),
)
}
}
}