Skip to content

Commit d80188f

Browse files
committed
fix: ajuste em httpclient error codes
1 parent 396d59d commit d80188f

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

internal/httpclient/errors/codes.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package errors
22

33
import (
44
"net/http"
5+
6+
"evo-ai-core-service/internal/infra/postgres"
57
)
68

79
// Standard error codes
@@ -144,6 +146,14 @@ func HandleError(err error) (code string, message string, httpCode int) {
144146
return apiErr.Code, apiErr.Message, apiErr.HTTPCode
145147
}
146148

149+
// Errors mapped from the database layer (postgres.MapDBError) carry their own
150+
// code + HTTP status (duplicate key → 409, record not found → 404, etc.). Sem
151+
// este ramo eles caíam no default abaixo e viravam 500/INTERNAL_ERROR — foi o
152+
// motivo de "API key with this name already exists" retornar 500 em vez de 409.
153+
if dbErr, ok := err.(*postgres.Error); ok {
154+
return string(dbErr.Code), dbErr.Message, dbErr.HTTPCode
155+
}
156+
147157
// Default to internal error
148158
return InternalError, err.Error(), http.StatusInternalServerError
149159
}

0 commit comments

Comments
 (0)