refactor: improve error interceptor

This commit is contained in:
Jonas Kaninda
2024-11-14 00:26:21 +01:00
parent 328703ad79
commit 42abf56473
15 changed files with 284 additions and 185 deletions

View File

@@ -22,6 +22,7 @@ import (
"github.com/jkaninda/goma-gateway/pkg/logger"
"io"
"net/http"
"slices"
)
func newResponseRecorder(w http.ResponseWriter) *responseRecorder {
@@ -62,6 +63,7 @@ func (intercept InterceptErrors) ErrorInterceptor(next http.Handler) http.Handle
if err != nil {
return
}
return
} else {
// No error: write buffered response to client
w.WriteHeader(rec.statusCode)
@@ -69,18 +71,12 @@ func (intercept InterceptErrors) ErrorInterceptor(next http.Handler) http.Handle
if err != nil {
return
}
return
}
})
}
func canIntercept(code int, errors []int) bool {
for _, er := range errors {
if er == code {
return true
}
continue
}
return false
return slices.Contains(errors, code)
}