modify doRequest() to return APIError on err

This commit is contained in:
Alfred Kamanda 2025-10-21 15:05:22 +03:00
parent 73e6220a8c
commit 6f7802b58c
Signed by: Alfred-mk
GPG Key ID: E60B2165A97F4D41

View File

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