Decode Gemini errors sent as a single object, not only as an array

Abierto
#484 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
swift

Línea de trabajo

Read JSONResponseErrorDecoder.decodeErrorResponse(data:) and the existing testAsyncChatsThrowsStatusErrorForSingleGeminiErrorObject test added in #471. First verify whether Gemini's OpenAI-compatible endpoint returns errors as a single object; the issue says this is unconfirmed. If it does, update decoding and the test to expect GeminiAPIErrorResponse; done means the caller receives the Gemini error message for that response.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

JSONResponseErrorDecoder recognizes a Gemini error only when it comes wrapped in an array:

[{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}]

The same error sent as a single object isn't recognized:

{"error": {"code": 400, "message": "Request contains an invalid argument.", "status": "INVALID_ARGUMENT"}}

It isn't an APIErrorResponse either, because type is required. So the caller never sees the message:

  • Before #471, the body surfaced as a DecodingError about the expected result type.
  • With #471, a status of 400 or above surfaces as OpenAIError.statusError, which carries no body.

The single-object shape is Google's standard API error format, which the native Gemini API uses. Nobody has confirmed yet whether the OpenAI-compatible endpoint ever returns it.

Proposal

  • Check whether Gemini's OpenAI-compatible endpoint returns errors as a single object.
  • If it does, make JSONResponseErrorDecoder.decodeErrorResponse(data:) also try a single GeminiAPIErrorResponse, so the caller gets the message.
  • Update testAsyncChatsThrowsStatusErrorForSingleGeminiErrorObject (added in #471) to expect a GeminiAPIErrorResponse.
Lenguaje dominante
Swift
Estrellas
2.9k
Forks
519
Merge medio
3 d 12 h
PR fusionados (30 d)
11

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de MacPaw/OpenAI

Todos los issues de MacPaw/OpenAI

Issues similares

Más issues de Swift

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.