Skip to content

Commit 2e89a06

Browse files
authored
feat(core): improve roundtripper error message (#1846)
* feat(core): improve roundtripper error message
1 parent 3744a2a commit 2e89a06

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## Release (2025-XX-YY)
2+
- `core`: [v0.17.1](core/CHANGELOG.md#v0171-2025-04-09)
3+
- **Improvement:** Improve error message for key flow authentication
4+
15
## Release (2025-04-09)
26
- `cdn`: [v0.3.0](services/cdn/CHANGELOG.md#v030-2025-04-04)
37
- **New:** Add waiter for creation of `CustomDomain`

core/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## v0.17.1 (2025-04-09)
2+
- **Improvement:** Improve error message for key flow authentication
3+
14
## v0.17.0 (2025-03-25)
25
- **New:** Helper functions for generic openapi error codes
36

core/clients/key_flow.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66
"crypto/x509"
77
"encoding/json"
88
"encoding/pem"
9+
"errors"
910
"fmt"
1011
"io"
1112
"net/http"
1213
"net/url"
14+
"regexp"
1315
"strings"
1416
"sync"
1517
"time"
@@ -209,7 +211,14 @@ func (c *KeyFlow) GetAccessToken() (string, error) {
209211
if !accessTokenExpired {
210212
return accessToken, nil
211213
}
212-
if err := c.recreateAccessToken(); err != nil {
214+
if err = c.recreateAccessToken(); err != nil {
215+
var oapiErr *oapierror.GenericOpenAPIError
216+
if ok := errors.As(err, &oapiErr); ok {
217+
reg := regexp.MustCompile("Key with kid .*? was not found")
218+
if reg.Match(oapiErr.Body) {
219+
err = fmt.Errorf("check if your configured key is valid and if the token endpoint is configured correct: %w", err)
220+
}
221+
}
213222
return "", fmt.Errorf("get new access token: %w", err)
214223
}
215224

0 commit comments

Comments
 (0)