aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAKP <abi@tdpain.net>2025-02-09 23:25:15 +0000
committerAKP <abi@tdpain.net>2025-02-09 23:25:15 +0000
commit0a94d685fd437bb27abc301ce9b1b72496316eaf (patch)
treeaf943b1298eeaf6813cf1f93b47e626cbdd28796
parent9fc768ba08b79ff7a90beca82b5f1e9ae54743da (diff)
Use errors.As in HTTP error handler
-rw-r--r--walrss/internal/http/http.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/walrss/internal/http/http.go b/walrss/internal/http/http.go
index 892b261..f76170c 100644
--- a/walrss/internal/http/http.go
+++ b/walrss/internal/http/http.go
@@ -2,6 +2,7 @@ package http
import (
"context"
+ "errors"
"github.com/codemicro/walrss/walrss/internal/core"
"github.com/codemicro/walrss/walrss/internal/http/views"
"github.com/codemicro/walrss/walrss/internal/state"
@@ -40,14 +41,18 @@ func New(st *state.State) (*Server, error) {
code := fiber.StatusInternalServerError
msg := "Internal Server Error"
- switch e := err.(type) {
- case *fiber.Error:
- code = e.Code
- msg = err.Error()
- case *core.UserError:
- code = e.Status
- msg = err.Error()
- default:
+ var (
+ fiberErr *fiber.Error
+ userErr *core.UserError
+ )
+
+ if errors.As(err, &fiberErr) {
+ code = fiberErr.Code
+ msg = fiberErr.Error()
+ } else if errors.As(err, &userErr) {
+ code = userErr.Status
+ msg = userErr.Error()
+ } else {
log.Error().Err(err).Str("location", "http").Str("url", ctx.OriginalURL()).Send()
}