Skip to content

Api error message#44

Merged
sxy-trans-n merged 2 commits intomainfrom
api-error-message
Jul 4, 2025
Merged

Api error message#44
sxy-trans-n merged 2 commits intomainfrom
api-error-message

Conversation

@sxy-trans-n
Copy link
Collaborator

Summary

Simplified error handling for both streaming and non-streaming chat completions to provide clearer, more transparent error messages to users.

Changes

  • Streaming errors: Send error messages via SSE chunks with finish_reason: "error" instead of trying to change HTTP status after headers are sent
  • Non-streaming errors: Return HTTP 500 with raw error message in JSON response
  • Removed error sanitization: Use error.localizedDescription directly for transparency
  • Added comprehensive unit tests: 14 test cases covering payload parsing, error formats, and response serialization

Benefits

  • ✅ OpenAI-compatible error responses
  • ✅ Clearer error messages for debugging
  • ✅ Consistent error handling between streaming/non-streaming
  • ✅ Robust test coverage for both error and success cases

Testing

All tests pass: swift test --filter CompletionsHandlerTests (14/14 ✅)

Copy link
Collaborator

@syh-trans-n syh-trans-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@sxy-trans-n sxy-trans-n merged commit 0f6bf29 into main Jul 4, 2025
2 checks passed
@sxy-trans-n sxy-trans-n deleted the api-error-message branch July 4, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants