8000 fix(ark): read the request ID from the x-request-id header on video e… · felinics/twilight@ce8dce6 · GitHub
[go: up one dir, main page]

Skip to content

Commit ce8dce6

Browse files
committed
fix(ark): read the request ID from the x-request-id header on video errors
Ark sends x-request-id on every error response, and the message quotes the same ID as "Request id". The decoder left RequestID empty. The new fixture is a 401 captured from ark.cn-beijing.volces.com.
1 parent d0ae284 commit ce8dce6

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

‎provider/ark/videos/errors.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ const providerName = "ark-videos"
1010

1111
// decodeError fills e from an Ark error body, which uses OpenAI's envelope:
1212
// {"error":{"code":"AuthenticationError","message":"...","param":"","type":"Unauthorized"}}.
13+
// The request ID is the x-request-id response header, the ID the message
14+
// quotes as "Request id".
1315
func decodeError(e *sdk.APIError) {
1416
errorformat.ParseOpenAI(e)
17+
e.RequestID = e.Header.Get("x-request-id")
1518
if k := kindFor(e.Code); k != sdk.KindUnknown {
1619
e.Kind = k
1720
}

‎provider/ark/videos/errors_test.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ func TestDecodeError(t *testing.T) {
1818
body := func(status, code, msg string) string {
1919
return `{"error":{"code":"` + code + `","message":"` + msg + `","param":"","type":"` + status + `"}}`
2020
}
21+
// Captured from ark.cn-beijing.volces.com on 2026-09-30 with an invalid key.
22+
const liveID = "021790757388403d5e3a06b1d3d650f0fc414a0e965c4997c2338"
23+
const liveMsg = "The API key format is incorrect. Request id: " + liveID
2124
cases := []providertest.ErrorCase{
25+
{Name: "live authentication", Status: 401, Header: http.Header{"X-Request-Id": {liveID}, "X-Error-Code": {"AuthN_AuthenticationError"}},
26+
Body: body("Unauthorized", "AuthenticationError", liveMsg),
27+
Want: sdk.APIError{Type: "Unauthorized", Code: "AuthenticationError", Message: liveMsg, RequestID: liveID, Kind: sdk.KindAuthentication}},
2228
{Name: "authentication", Status: 401, Body: body("Unauthorized", "AuthenticationError", "The API key or AK/SK in the request is missing or invalid. Request ID: 1."),
2329
Want: sdk.APIError{Type: "Unauthorized", Code: "AuthenticationError", Message: "The API key or AK/SK in the request is missing or invalid. Request ID: 1.", Kind: sdk.KindAuthentication}},
2430
{Name: "overdue is 403", Status: 403, Body: body("Forbidden", "AccountOverdueError", "overdue"),

0 commit comments

Comments
 (0)
0