parseOpenAIHTTPError parses OpenAI API HTTP error responses
(resp *http.Response)
| 579 | |
| 580 | // parseOpenAIHTTPError parses OpenAI API HTTP error responses |
| 581 | func parseOpenAIHTTPError(resp *http.Response) error { |
| 582 | body, err := io.ReadAll(resp.Body) |
| 583 | if err != nil { |
| 584 | return fmt.Errorf("openai %s: failed to read error response: %v", resp.Status, err) |
| 585 | } |
| 586 | |
| 587 | logutil.DevPrintf("openai full error: %s\n", body) |
| 588 | |
| 589 | // Try to parse as OpenAI error format first |
| 590 | var errorResp openAIErrorResponse |
| 591 | if err := json.Unmarshal(body, &errorResp); err == nil && errorResp.Error.Message != "" { |
| 592 | return fmt.Errorf("openai %s: %s", resp.Status, errorResp.Error.Message) |
| 593 | } |
| 594 | |
| 595 | // Try to parse as proxy error format |
| 596 | var proxyErr uctypes.ProxyErrorResponse |
| 597 | if err := json.Unmarshal(body, &proxyErr); err == nil && !proxyErr.Success && proxyErr.Error != "" { |
| 598 | return fmt.Errorf("openai %s: %s", resp.Status, proxyErr.Error) |
| 599 | } |
| 600 | |
| 601 | return fmt.Errorf("openai %s: %s", resp.Status, utilfn.TruncateString(string(body), 120)) |
| 602 | } |
| 603 | |
| 604 | // handleOpenAIStreamingResp handles the OpenAI SSE streaming response |
| 605 | func handleOpenAIStreamingResp(ctx context.Context, sse *sse.SSEHandlerCh, decoder *eventsource.Decoder, cont *uctypes.WaveContinueResponse, chatOpts uctypes.WaveChatOpts) (*uctypes.WaveStopReason, []*OpenAIChatMessage) { |
no test coverage detected