aboutsummaryrefslogtreecommitdiffstats
path: root/dashboard/app/handler.go
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-07-24 11:17:03 +0200
committerTaras Madan <tarasmadan@google.com>2024-07-24 11:15:34 +0000
commitb5362d58b9f04972fc664a4ce7d7b4b6a8fb0d33 (patch)
tree5b660c10553287f20e53529df170f7439f0bf528 /dashboard/app/handler.go
parent5901baceb4f56b65b0a64abd8ae279fc56349067 (diff)
dashboard/app/api.go: handleAPI can return less 5xx errors
Diffstat (limited to 'dashboard/app/handler.go')
-rw-r--r--dashboard/app/handler.go25
1 files changed, 15 insertions, 10 deletions
diff --git a/dashboard/app/handler.go b/dashboard/app/handler.go
index 145f79ef9..91c051e2b 100644
--- a/dashboard/app/handler.go
+++ b/dashboard/app/handler.go
@@ -60,16 +60,7 @@ func handleContext(fn contextHandler) http.Handler {
return
}
- status := http.StatusInternalServerError
- logf := log.Errorf
- var clientError *ErrClient
- if errors.As(err, &clientError) {
- // We don't log these as errors because they can be provoked
- // by invalid user requests, so we don't wan't to pollute error log.
- logf = log.Warningf
- status = clientError.HTTPStatus()
- }
- logf(c, "%v", err)
+ status := logErrorPrepareStatus(c, err)
w.WriteHeader(status)
if err1 := templates.ExecuteTemplate(w, "error.html", data); err1 != nil {
combinedError := fmt.Sprintf("got err \"%v\" processing ExecuteTemplate() for err \"%v\"", err1, err)
@@ -79,6 +70,20 @@ func handleContext(fn contextHandler) http.Handler {
})
}
+func logErrorPrepareStatus(c context.Context, err error) int {
+ status := http.StatusInternalServerError
+ logf := log.Errorf
+ var clientError *ErrClient
+ if errors.As(err, &clientError) {
+ // We don't log these as errors because they can be provoked
+ // by invalid user requests, so we don't wan't to pollute error log.
+ logf = log.Warningf
+ status = clientError.HTTPStatus()
+ }
+ logf(c, "%v", err)
+ return status
+}
+
func isRobot(r *http.Request) bool {
userAgent := strings.ToLower(strings.Join(r.Header["User-Agent"], " "))
if strings.HasPrefix(userAgent, "curl") ||