MSP-7042 Init service

This commit is contained in:
Синельник Тимур Романович committed 2026-01-27 15:37:25 +03:00
1 parent aecc42c6d8
commit 25a51652e6
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)
})
}
}