MCPcopy
hub / github.com/wavetermdev/waveterm / parseOpenAIHTTPError

Function parseOpenAIHTTPError

pkg/aiusechat/openai/openai-backend.go:581–602  ·  view source on GitHub ↗

parseOpenAIHTTPError parses OpenAI API HTTP error responses

(resp *http.Response)

Source from the content-addressed store, hash-verified

579
580// parseOpenAIHTTPError parses OpenAI API HTTP error responses
581func 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
605func handleOpenAIStreamingResp(ctx context.Context, sse *sse.SSEHandlerCh, decoder *eventsource.Decoder, cont *uctypes.WaveContinueResponse, chatOpts uctypes.WaveChatOpts) (*uctypes.WaveStopReason, []*OpenAIChatMessage) {

Callers 1

RunOpenAIChatStepFunction · 0.85

Calls 3

DevPrintfFunction · 0.92
TruncateStringFunction · 0.92
ReadAllMethod · 0.45

Tested by

no test coverage detected