From eb8da5b48ca866f50642e7cfd7c588b606c01b09 Mon Sep 17 00:00:00 2001 From: fylorn <249551762+fylorn@users.noreply.github.com> Date: Tue, 29 Sep 2026 02:11:56 +0800 Subject: [PATCH] fix(gateway): say a refusal without an exception name in its own sentence When AWS refused a Bedrock credential without naming the exception, the refusal filled the English phrase "no exception name" into the `{kind}` slot of `gw.upstream.bedrock_refused`, so a translated interface showed an untranslated fragment. That case now has its own code and sentence, `gw.upstream.bedrock_refused_unnamed`. Co-Authored-By: Claude Opus 5.5 --- crates/tw-api/msg-codes.txt | 1 + crates/tw-gateway/src/server/pipeline/hop.rs | 14 +++++++++--- crates/tw-gateway/tests/bedrock.rs | 24 ++++++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/crates/tw-api/msg-codes.txt b/crates/tw-api/msg-codes.txt index f324c5c5..91c38c63 100644 --- a/crates/tw-api/msg-codes.txt +++ b/crates/tw-api/msg-codes.txt @@ -277,6 +277,7 @@ gw.toolcall.cut gw.upstream.aws_profile_expired gw.upstream.aws_token_expired gw.upstream.bedrock_refused +gw.upstream.bedrock_refused_unnamed gw.upstream.eventstream_broken gw.upstream.forward_failed gw.upstream.rate_limited diff --git a/crates/tw-gateway/src/server/pipeline/hop.rs b/crates/tw-gateway/src/server/pipeline/hop.rs index da93df34..2984ca26 100644 --- a/crates/tw-gateway/src/server/pipeline/hop.rs +++ b/crates/tw-gateway/src/server/pipeline/hop.rs @@ -800,14 +800,22 @@ async fn bedrock_refusal( "[ThinkWatch] The temporary AWS credential of upstream `{upstream}` has expired. \ Replace its session token and the access keys that came with it." ), - (other, _) => msg!( + (Some(kind), _) => msg!( "gw.upstream.bedrock_refused", - upstream = provider.name.clone(), status = status.as_u16(), - kind = other.unwrap_or("no exception name") => + upstream = provider.name.clone(), status = status.as_u16(), kind = kind => "[ThinkWatch] AWS refused the credential of upstream `{upstream}` (HTTP {status}, \ {kind}). Check that the credential is valid and may use this model. AWS's own \ message names the account, so it is not passed on." ), + // AWS 没说是哪种异常:另一句话,不拿一个英文词组去填 `{kind}` —— 那一格在译文里 + // 就是一段没翻译的英文 + (None, _) => msg!( + "gw.upstream.bedrock_refused_unnamed", + upstream = provider.name.clone(), status = status.as_u16() => + "[ThinkWatch] AWS refused the credential of upstream `{upstream}` (HTTP {status}). \ + Check that the credential is valid and may use this model. AWS's own message names \ + the account, so it is not passed on." + ), }; for h in ["content-length", "content-type", "transfer-encoding"] { headers.remove(h); diff --git a/crates/tw-gateway/tests/bedrock.rs b/crates/tw-gateway/tests/bedrock.rs index 6f9f7cad..4a410475 100644 --- a/crates/tw-gateway/tests/bedrock.rs +++ b/crates/tw-gateway/tests/bedrock.rs @@ -439,6 +439,30 @@ async fn a_refused_credential_does_not_pass_on_what_aws_said_about_the_account() assert!(body.contains("[ThinkWatch]"), "{body}"); } +/// AWS 没说是哪种异常:换一句话说,不在句子里填一个英文词组(译文里那一格会是英文) +#[tokio::test] +async fn a_refusal_without_an_exception_name_is_its_own_sentence() { + let (up, _) = bedrock(Arc::new(|_| { + json_answer( + 403, + json!({"message": "User: arn:aws:iam::123456789012:user/alice is not authorized"}), + ) + })) + .await; + let (gw, _, _) = gateway(with_keys(up)).await; + let (status, body) = post( + gw, + "/v1/messages", + &[("x-api-key", "tw-k")], + json!({"model": MODEL, "max_tokens": 16, "messages": [{"role": "user", "content": "hi"}]}), + ) + .await; + assert_eq!(status, 403); + assert!(!body.contains("123456789012"), "{body}"); + assert!(body.contains("(HTTP 403)."), "{body}"); + assert!(!body.contains("exception name"), "{body}"); +} + #[tokio::test] async fn cache_points_and_the_betas_bedrock_takes_reach_it() { let (up, seen) = bedrock(Arc::new(|_| json_answer(200, converse_reply("ok")))).await;