Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/tw-api/msg-codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions crates/tw-gateway/src/server/pipeline/hop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions crates/tw-gateway/tests/bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading