Files
new-api-custom/controller/relay_client_error_test.go
T
Codex bb7968b612
Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
feat: publish v1.0.0-rc.36-custom.1
2026-09-11 05:07:48 +08:00

46 lines
1.7 KiB
Go

package controller
import (
"errors"
"net/http"
"strings"
"testing"
"github.com/QuantumNous/new-api/relaykit/types"
)
func TestClientFacingOpenAIErrorHidesUpstreamDetails(t *testing.T) {
err := types.NewOpenAIError(errors.New("provider.example.invalid provider secret failure"), types.ErrorCodeBadResponseStatusCode, http.StatusBadGateway)
got := clientFacingOpenAIError(err, true, "local-request-id")
if strings.Contains(got.Message, "example-provider") || strings.Contains(got.Message, "provider secret") {
t.Fatalf("upstream details leaked: %q", got.Message)
}
if !strings.Contains(got.Message, "local-request-id") {
t.Fatalf("local request id missing: %q", got.Message)
}
if got.Code != "model_service_error" {
t.Fatalf("unexpected public code: %v", got.Code)
}
}
func TestClientFacingClaudeErrorHidesUpstreamDetails(t *testing.T) {
err := types.NewOpenAIError(errors.New("provider.example.invalid provider secret failure"), types.ErrorCodeBadResponseStatusCode, http.StatusBadGateway)
got := clientFacingClaudeError(err, true, "local-request-id")
if strings.Contains(got.Message, "example-provider") || strings.Contains(got.Message, "provider secret") {
t.Fatalf("upstream details leaked: %q", got.Message)
}
if !strings.Contains(got.Message, "local-request-id") {
t.Fatalf("local request id missing: %q", got.Message)
}
}
func TestClientFacingErrorKeepsLocalValidationMessage(t *testing.T) {
err := types.NewErrorWithStatusCode(errors.New("model is required"), types.ErrorCodeInvalidRequest, http.StatusBadRequest)
got := clientFacingOpenAIError(err, false, "local-request-id")
if !strings.Contains(got.Message, "model is required") {
t.Fatalf("local validation message was hidden: %q", got.Message)
}
}