Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit d42d098

Browse files
committed
update error handling for invalid/expired API key or quota reached
1 parent e717329 commit d42d098

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

runtime/models/models.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,17 @@ func PostToModelEndpoint[TResult any](ctx context.Context, model *manifest.Model
9393
var empty TResult
9494
var httpe *utils.HttpError
9595
if errors.As(err, &httpe) {
96-
if app.IsDevEnvironment() && httpe.StatusCode == http.StatusNotFound {
97-
return empty, fmt.Errorf("model %s is not available in the local dev environment", model.SourceModel)
96+
switch httpe.StatusCode {
97+
case http.StatusNotFound:
98+
if app.IsDevEnvironment() {
99+
return empty, fmt.Errorf("model %s is not available in the local dev environment", model.SourceModel)
100+
}
101+
case http.StatusUnauthorized:
102+
return empty, fmt.Errorf("invalid or expired API key")
103+
case http.StatusForbidden:
104+
return empty, fmt.Errorf("API key is disabled or usage limit exceeded")
105+
case http.StatusTooManyRequests:
106+
return empty, fmt.Errorf("rate limit exceeded")
98107
}
99108
}
100109

0 commit comments

Comments
 (0)