TestChatStructuredErrorPrefersProviderHint: the hamrpass proxy wraps upstream errors as `{"error":{"message":...,"provider_hint":...}}`. The client must surface provider_hint over message, so users see the useful "retry shortly" text, not "upstream rate limited".
(t *testing.T)
| 545 | } |
| 546 | } |
| 547 | |
| 548 | // TestChatStructuredErrorPrefersProviderHint: the hamrpass proxy wraps upstream |
| 549 | // errors as `{"error":{"message":...,"provider_hint":...}}`. The client must |
| 550 | // surface provider_hint over message, so users see the useful "retry shortly" |
| 551 | // text, not "upstream rate limited". |
| 552 | func TestChatStructuredErrorPrefersProviderHint(t *testing.T) { |
| 553 | srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { |
| 554 | w.Header().Set("Content-Type", "application/json") |
| 555 | w.WriteHeader(http.StatusTooManyRequests) |
| 556 | fmt.Fprint(w, `{"error":{"message":"upstream rate limited","type":"rate_limited","upstream_status":429,"provider_hint":"the upstream model is temporarily rate-limited, retry shortly"}}`) |
| 557 | })) |
| 558 | defer srv.Close() |
| 559 | c := New(srv.URL, "m", "") |
| 560 | c.RetryBackoff = nil // pin the terminal error surface, not the retry path |
| 561 | evs := collect(c.Chat(context.Background(), nil, nil)) |
| 562 | if len(evs) != 1 || evs[0].Kind != EventError { |
| 563 | t.Fatalf("want single error event, got %+v", evs) |
| 564 | } |
| 565 | if !strings.Contains(evs[0].Err.Error(), "429") { |
| 566 | t.Fatalf("error should include upstream status: %v", evs[0].Err) |
| 567 | } |
| 568 | if !strings.Contains(evs[0].Err.Error(), "retry shortly") { |
| 569 | t.Fatalf("error should surface provider_hint: %v", evs[0].Err) |
| 570 | } |