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 31a3503021
commit ecd0120920
10 changed files with 43 additions and 49 deletions

View file

@ -1,6 +1,7 @@
package middleware
import (
"fmt"
"net/http"
"strconv"
@ -32,11 +33,10 @@ 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)
return echo.NewHTTPError(
http.StatusInternalServerError,
fmt.Sprintf("error querying user: %v", err),
)
}
}
}