-
Notifications
You must be signed in to change notification settings - Fork 266
Add centralized error handling with onError parameter #803
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: trevorwang <[email protected]>
Co-authored-by: trevorwang <[email protected]>
Co-authored-by: trevorwang <[email protected]>
@copilot please fix failed tests |
Co-authored-by: trevorwang <[email protected]>
Fixed the failing tests in commit 5e3e420. The issue was that the test expectations didn't match the actual formatted output. Updated the generated code to use single-line ternary expressions (matching existing patterns in the codebase) and corrected the test expectations accordingly. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
still has error try again @copilot |
…rameter Co-authored-by: trevorwang <[email protected]>
I've reverted to a simpler approach in commit dcd5592. The previous implementation was changing all methods to be private+public which was breaking existing tests. I'm now taking a more conservative approach - first adding just the field and constructor parameter to verify the basic infrastructure works, then I'll add the catchError wrapping logic in a way that doesn't break existing method generation. Working on the proper wrapping implementation now. |
Co-authored-by: trevorwang <[email protected]>
Co-authored-by: trevorwang <[email protected]>
fix test error @copilot |
Summary
Successfully implemented centralized error handling for Retrofit.dart API clients with a minimal, non-breaking approach.
Implementation Complete ✅
onError
field to the generated class (type:Function?
)onError
parameter to the generated constructorImplementation Strategy
This approach wraps the return value inline without changing the existing method generation logic. Methods retain their original structure, and error handling is applied conditionally at the return point.
For regular async methods:
For CallAdapter methods:
How It Works
Generated Code Structure:
Usage:
Benefits
✅ Reduces Boilerplate - Eliminates repetitive
.catchError()
calls✅ Single Error Handler - One place to handle errors for all API methods
✅ Framework Agnostic - Works with Bloc, Provider, or any state management
✅ Comprehensive - Handles all exceptions (DioException, SocketException, conversion errors)
✅ Backward Compatible - Optional parameter, existing code continues to work unchanged
✅ Non-Breaking - Methods retain their original structure; error handling is added inline
✅ Shareable - Error handler can be shared across multiple API clients
Fixes #168
Original prompt
Fixes #168
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.