From 02cc03e744fc697202be9f4a70d64d0eb20b5f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=83=D0=B7=D0=BD=D0=B5=D1=86=D0=BE=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B4=D1=80=D0=BE=D0=B2=D0=B8=D1=87?= Date: Thu, 3 Apr 2025 16:39:06 +0300 Subject: [PATCH] MSP-5160 refactoring HttpError --- httperrors/errors.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/httperrors/errors.go b/httperrors/errors.go index e71f6ab..3eed92f 100644 --- a/httperrors/errors.go +++ b/httperrors/errors.go @@ -6,27 +6,26 @@ import ( "github.com/txix-open/isp-kit/json" ) -// nolint: recvcheck type HttpError struct { statusCode int userMessage string - details []interface{} + details []any err error } -func New(statusCode int, userMessage string, internalError error) HttpError { - return HttpError{ +func New(statusCode int, userMessage string, internalError error) *HttpError { + return &HttpError{ statusCode: statusCode, userMessage: userMessage, err: internalError, } } -func (e HttpError) Error() string { +func (e *HttpError) Error() string { return e.err.Error() } -func (e HttpError) WriteError(w http.ResponseWriter) error { +func (e *HttpError) WriteError(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(e.statusCode) data := map[string]interface{}{ @@ -37,6 +36,6 @@ func (e HttpError) WriteError(w http.ResponseWriter) error { return json.NewEncoder(w).Encode(data) } -func (e *HttpError) WithDetails(details ...interface{}) { +func (e *HttpError) WithDetails(details ...any) { e.details = details }