2026-02-11 16:56:17: merge [main:afeadb1d9a241da30507f3683781558dbccfefc6];
Create and publish a Docker image / build-and-push-image (push) Canceled after 0s

This commit is contained in:
txix committed 2026-02-11 16:56:17 +03:00
1 parent aecc42c6d8
commit d4091f8805
25 files changed
+1664 -92

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
package middleware
import (
"context"
"net/http"
"isp-router-service/domain"
http2 "github.com/txix-open/isp-kit/http"
"github.com/txix-open/isp-kit/log"
)
type HttpError interface {
WriteError(w http.ResponseWriter) error
}
func ErrorHandler(logger log.Logger) http2.Middleware {
return func(next http2.HandlerFunc) http2.HandlerFunc {
return http2.HandlerFunc(func(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
err := next(ctx, w, r)
if err == nil {
return nil
}
logger.Error(ctx, err)
httpErr, ok := err.(HttpError)
if ok {
return httpErr.WriteError(w)
}
return domain.NewHttpError(http.StatusInternalServerError, "internal service error", err).
WriteError(w)
})
}
}