From 73e6220a8cef5ad6d44e3d138ecf332c9f879478 Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Tue, 21 Oct 2025 15:02:36 +0300 Subject: [PATCH 1/3] create a custom error struct that carries both fields from the API --- remote/http/service.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/remote/http/service.go b/remote/http/service.go index c17b0d1..4286997 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -27,6 +27,15 @@ var ( logg = logging.NewVanilla().WithDomain("sarafu-api.devapi") ) +type APIError struct { + Code string + Description string +} + +func (e *APIError) Error() string { + return e.Description +} + type HTTPAccountService struct { SS storage.StorageService UseApi bool -- 2.45.2 From 6f7802b58cf52e1dc65fdf6175515859244b63b1 Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Tue, 21 Oct 2025 15:05:22 +0300 Subject: [PATCH 2/3] modify doRequest() to return APIError on err --- remote/http/service.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/remote/http/service.go b/remote/http/service.go index 4286997..d5b850a 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -771,7 +771,11 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons if err := json.Unmarshal(body, &errResponse); err != nil { return nil, err } - return nil, errors.New(errResponse.Description) + + return nil, &APIError{ + Code: errResponse.ErrCode, + Description: errResponse.Description, + } } if err := json.Unmarshal(body, &okResponse); err != nil { @@ -779,7 +783,7 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons } if len(okResponse.Result) == 0 { - return nil, errors.New("Empty api result") + return nil, errors.New("empty api result") } v, err := json.Marshal(okResponse.Result) -- 2.45.2 From 532547899f634b3b8a5fd8c200faab52610aba8e Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Wed, 22 Oct 2025 11:46:13 +0300 Subject: [PATCH 3/3] include the error code --- remote/http/service.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/remote/http/service.go b/remote/http/service.go index d5b850a..f1f8d55 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -33,6 +33,9 @@ type APIError struct { } func (e *APIError) Error() string { + if e.Code != "" { + return fmt.Sprintf("[%s] %s", e.Code, e.Description) + } return e.Description } -- 2.45.2