Handle context cancellations and avoid logged errors.
This commit is contained in:
parent
0f7da0864e
commit
acd38c8205
8 changed files with 83 additions and 35 deletions
|
|
@ -24,6 +24,9 @@ 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)
|
||||
}
|
||||
|
||||
|
|
@ -55,6 +58,9 @@ 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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,11 +51,15 @@ func ServeCachedPage(ch *cache.Cache) echo.MiddlewareFunc {
|
|||
new(CachedPage),
|
||||
)
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
switch {
|
||||
case err == redis.Nil:
|
||||
c.Logger().Info("no cached page found")
|
||||
} else {
|
||||
case context.IsCanceledError(err):
|
||||
return nil
|
||||
default:
|
||||
c.Logger().Errorf("failed getting cached page: %v", err)
|
||||
}
|
||||
|
||||
return next(c)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@ func LoadUser(orm *ent.Client) echo.MiddlewareFunc {
|
|||
case *ent.NotFoundError:
|
||||
return echo.NewHTTPError(http.StatusNotFound)
|
||||
default:
|
||||
if context.IsCanceledError(err) {
|
||||
return nil
|
||||
}
|
||||
c.Logger().Error(err)
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue