Files
Luminary/internal/handler/proxy/errors.go
T
renjue 76ba500417
CI / docker (push) Successful in 2m4s
Initial commit: Luminary AI Gateway
OpenAI-compatible AI gateway with Vue admin UI, multi-provider egress,
ingress key governance, monitoring, and security controls.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-23 21:46:16 +08:00

31 lines
787 B
Go

package proxy
import (
"errors"
"net/http"
"strings"
"github.com/rose_cat707/luminary/internal/gateway"
)
func gatewayHTTPStatus(err error) int {
switch {
case errors.Is(err, gateway.ErrRateLimitExceeded):
return http.StatusTooManyRequests
case errors.Is(err, gateway.ErrModelNotAllowed),
errors.Is(err, gateway.ErrBudgetExceeded):
return http.StatusForbidden
case errors.Is(err, gateway.ErrInvalidJSON),
errors.Is(err, gateway.ErrModelRequired):
return http.StatusBadRequest
}
msg := err.Error()
if strings.Contains(msg, "not enabled") || strings.Contains(msg, "not allowed") {
return http.StatusForbidden
}
if strings.Contains(msg, "invalid api key") || strings.Contains(msg, "expired") {
return http.StatusUnauthorized
}
return http.StatusBadGateway
}