diff --git a/remote/http/service.go b/remote/http/service.go index c17b0d1..f1f8d55 100644 --- a/remote/http/service.go +++ b/remote/http/service.go @@ -27,6 +27,18 @@ var ( logg = logging.NewVanilla().WithDomain("sarafu-api.devapi") ) +type APIError struct { + Code string + Description string +} + +func (e *APIError) Error() string { + if e.Code != "" { + return fmt.Sprintf("[%s] %s", e.Code, e.Description) + } + return e.Description +} + type HTTPAccountService struct { SS storage.StorageService UseApi bool @@ -762,7 +774,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 { @@ -770,7 +786,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)