Compare commits

...

4 Commits

Author SHA1 Message Date
Alfred Kamanda
532547899f include the error code 2025-10-22 11:46:13 +03:00
Alfred Kamanda
6f7802b58c modify doRequest() to return APIError on err 2025-10-21 15:05:22 +03:00
Alfred Kamanda
73e6220a8c create a custom error struct that carries both fields from the API 2025-10-21 15:02:36 +03:00
8d4fbb9c2e Merge pull request 'Normalize symbols before returning' (#17) from sanitize-symbols into master
Reviewed-on: #17

Merged after successful tests
2025-10-06 11:02:42 +02:00

View File

@@ -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)