Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ahmedtalal
Copy link

Changed in ChopperException class to handle HTTP errors in a clear and structured way. This improves error reporting and makes it easier to manage failed responses gracefully.
Kindly consider accepting the request if it fits the direction of the project. 🙏

@techouse
Copy link
Collaborator

techouse commented May 22, 2025

Hi,

While I appreciate the effort, this is far too naive and needs a lot more work + the mandatory tests.

There are a couple dozen of HTTP exceptions to handle and a simple enum just won't do.

FYI I have created a Chopper plugin for Talker for pretty-printing errors Frezyx/talker#355 and it should come out in the next major release. This PR here could enhance the data it receives from the ChopperException.

@Guldem care to throw an eye on this?

@techouse techouse marked this pull request as draft May 22, 2025 12:52
@techouse techouse self-assigned this May 22, 2025
@techouse techouse added the enhancement New feature or request label May 22, 2025
unknown,
}

extension ChopperExceptionTypeDescription on ChopperExceptionType {
Copy link
Collaborator

Choose a reason for hiding this comment

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

With enhanced enums in Dart 3, creating extensions like these is no longer necessary. You can simply add a the method toPrettyDescription to the ChopperExceptionType enum.

throw ChopperException(
request: request,
type: ChopperExceptionType.unknown,
error:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the benefit of all of this? The type is unknown and the error is basically the same.

throw ChopperException(
request: chain.request,
type: ChopperExceptionType.unknown,
error: 'Unsupported response type: ${BodyType.runtimeType}',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than writing a "pretty" message, this the ChopperException should consume a StackTrace

@Guldem
Copy link
Contributor

Guldem commented May 26, 2025

Extending the ChopperException class or providing more details is fine by me. But like @techouse said, this is not a complete solution and needs more work.

But I missing the point of providing Http information in the ChopperException. Chopper doesn't throw this exception based on response status. It's only thrown when something goes wrong internally or a interceptor is wrongfully configured.

There is a ChopperHttpException which might get thrown when the ChopperService is configured without the Response object. See

BodyType get bodyOrThrow {
and https://github.com/lejard-h/chopper/blob/develop/getting-started.md#defining-a-request

Still not sure if the package should do the error handling for http responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants