This commit is contained in:
aafetisov committed 2026-10-16 15:40:34 +03:00
1 parent 70edc100d5
commit 5825bdfa9e
65 files changed
+1061 -302

No files matched your search

+7 -13
View File
@@ -5,7 +5,6 @@ import (
"context"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
@@ -127,7 +126,7 @@ func (bdc *BVSDecortClient) DecortApiCall(ctx context.Context, method, url strin
}
// get token and retry in case of access denied
if err.Error() == "access is denied" {
if HasStatusCode(err, http.StatusUnauthorized) {
_, err = bdc.GetToken(ctx)
if err != nil {
return nil, err
@@ -193,7 +192,7 @@ func (bdc *BVSDecortClient) DecortApiCallCtype(ctx context.Context, method, url,
}
// get token and retry in case of access denied
if err.Error() == "access is denied" {
if HasStatusCode(err, http.StatusUnauthorized) {
_, err = bdc.GetToken(ctx)
if err != nil {
return nil, err
@@ -243,7 +242,7 @@ func (bdc *BVSDecortClient) DecortApiCallMP(ctx context.Context, method, url str
}
// get token and retry in case of access denied
if err.Error() == "access is denied" {
if HasStatusCode(err, http.StatusUnauthorized) {
_, err = bdc.GetToken(ctx)
if err != nil {
return nil, err
@@ -287,7 +286,7 @@ func (bdc *BVSDecortClient) GetToken(ctx context.Context) (config.Token, error)
}
if resp.StatusCode != 200 {
return config.Token{}, fmt.Errorf("cannot get token: %s", tokenBytes)
return config.Token{}, newHTTPError("cannot get token", resp.StatusCode, tokenBytes)
}
// save token in config
@@ -346,7 +345,7 @@ func (bdc *BVSDecortClient) RefreshToken(ctx context.Context) (config.Token, err
}
if resp.StatusCode != 200 {
return config.Token{}, fmt.Errorf("cannot refresh token: %s", tokenBytes)
return config.Token{}, newHTTPError("cannot refresh token", resp.StatusCode, tokenBytes)
}
// save token in config
@@ -452,17 +451,12 @@ func (bdc *BVSDecortClient) do(req *http.Request, ctype string) ([]byte, error)
return nil, err
}
// handle access denied and successful request
if resp.StatusCode == 401 {
return respBytes, errors.New("access is denied")
}
if resp.StatusCode == 200 {
return respBytes, nil
}
// handle errors with other status codes
err = fmt.Errorf("%s", respBytes)
return nil, fmt.Errorf("could not execute request: %w", err)
// handle errors with status code other than 200 (401 triggers token refresh in callers)
return nil, newHTTPError("could not execute request", resp.StatusCode, respBytes)
}
func trimBVSConfig(cfg *config.BVSConfig) config.BVSConfig {