Skip to content

Added API error separation by their HTTP codes #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LuckThemAll
Copy link

@LuckThemAll LuckThemAll commented Jun 30, 2024

What:

  • Bug Fix
  • New Feature

Description:

Added separation of API errors by their HTTP codes. This enhancement improves error handling by categorizing errors based on their HTTP status codes, allowing for more precise error management and debugging.

Related:

#402

Comment on lines 62 to 66
$contents = $response->getBody()->getContents();

if (str_contains($response->getHeaderLine('Content-Type'), ContentType::TEXT_PLAIN->value)) {
return Response::from($contents, $response->getHeaders());
}

Choose a reason for hiding this comment

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

The work in this PR looks good but I'm seeing intermittent requests failing due to OpenAI API flakeyness (#478). This block needs some of the precautions of throwIfJsonError() otherwise the string response data starts causing TypeError.

Status Code: 404
Content-Type: "text\/plain; charset=utf-8"
Body: "404 page not found\n"

@iBotPeaches iBotPeaches marked this pull request as draft April 8, 2025 23:54
@iBotPeaches
Copy link
Collaborator

Marking as draft due to test failures & conflicts. Sorry for delay.

@bytestream
Copy link

@iBotPeaches is this something you'd accept if I resubmit the PR?

@iBotPeaches
Copy link
Collaborator

@bytestream - You like hitting me with all the Exception related ones :) - A bit torn on this one because this library is used for so many more services than just OpenAI and it seems to make some large assumptions on HTTP code and introduce a lot more exceptions.

I think for me the improvements to make are:

  • stop crashing when throwing an exception
  • include the response in the existing relevant exceptions

Those are a bit easier in my head to accept.

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.

3 participants