Check the HTTP status code for JSON responses
Los mantenedores suelen responder en 3 días
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Start with Sources/OpenAI/Private/JSONResponseDecoder.swift and URLResponseHandler, then compare the existing status handling in StreamingSession and throwIfErrorStatus. Check relaxed parsing behavior for supported providers and add non-2xx tests for completion-handler, async, and Combine requests, including API and non-API error bodies. Done when all four response paths handle transport errors and status codes consistently and the CHANGELOG describes the changed errors.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
JSON requests never check the HTTP status code. They seem to handle API errors only because JSONResponseDecoder falls back to decoding an API error when the expected result type fails to decode (Sources/OpenAI/Private/JSONResponseDecoder.swift). That fallback misses two cases:
- The error body isn't an API error, such as an HTML page from a proxy or gateway. The caller gets a
DecodingErrorabout the expected type instead of an error carrying the status code. - The error body decodes as the expected type. With
.relaxedparsing, which fills in missing required fields, an error body could decode into a result with default values and be returned as a success.
#401 adds a status check for responses read as raw data (files.content(id:) and audioCreateSpeech), in URLResponseHandler.throwIfErrorStatus. It throws the decoded APIErrorResponse for a status of 400 or above, falling back to OpenAIError.statusError, as StreamingSession already does. JSON responses were left out because changing them affects every endpoint.
Proposal
- Route all four
URLResponseHandlermethods (JSON and raw, with and without anerror:parameter) through one function, probablyunwrapwith theresponseadded, that throws a transport error first and then checks the status. That way completion-handler, async and Combine requests behave the same. - Check that providers supported through
.relaxedparsing still work, in particular whether any of them return successful responses with a status of 400 or above, or error bodies in a shapeJSONResponseErrorDecoderdoesn't know. - Add tests with a non-2xx status and an error body, and with a non-API body, for all three flavours.
This changes what JSON requests throw in some error cases (OpenAIError.statusError instead of a DecodingError), so it needs a CHANGELOG entry.
- Lenguaje dominante
- Swift
- Estrellas
- 2.9k
- Forks
- 519
- Merge medio
- 4 d 9 h
- PR fusionados (30 d)
- 13
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de MacPaw/OpenAI
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 3 días
-
Enable batch promptsAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
MacPaw/OpenAI#73 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 3 días
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
Los mantenedores suelen responder en 3 días
-
Add Batch API supportAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 3 días
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 3 días
Todos los issues de MacPaw/OpenAI
Issues similares
-
builtin-port enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
cmlarsen/writemorebetter#235 ·
Los mantenedores suelen responder en 1 día
-
bug-pending-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
NativeScript/NativeScript#11525 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
callstack/agent-device#3627 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
maziyarpanahi/openmed#4207 · 1 comentario ·
Los mantenedores suelen responder en 3 días