Skip to content

Commit

Permalink
Transform HTTP 403 (Forbidden) error returned by VertexAI API (#55)
Browse files Browse the repository at this point in the history
The `VertexAdapater.TransformError` method was not handling HTTP 403
errors, resulting in a failed unmarshal into a standard anthropic
`ResponseError`.
  • Loading branch information
Mrmann87 authored Dec 12, 2024
1 parent 28810ea commit 7bf5cad
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions vertexadapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ type VertexAdapter struct {
}

func (v *VertexAdapter) TranslateError(resp *http.Response, body []byte) (error, bool) {
if resp.StatusCode == 401 || resp.StatusCode == 404 || resp.StatusCode == 429 {
switch resp.StatusCode {
case http.StatusUnauthorized,
http.StatusForbidden,
http.StatusNotFound,
http.StatusTooManyRequests:
var errRes VertexAIErrorResponse
err := json.Unmarshal(body, &errRes)
if err != nil {
Expand All @@ -38,7 +42,6 @@ func (v *VertexAdapter) TranslateError(resp *http.Response, body []byte) (error,
errRes.Error,
), true
}

return nil, false
}

Expand Down

0 comments on commit 7bf5cad

Please sign in to comment.