Skip to content

Conversation

@techouse
Copy link
Contributor

@techouse techouse commented May 6, 2025

This pull request introduces several enhancements and refactors across the codebase, focusing on improving error handling, adopting modern Dart patterns, and enhancing code readability. Key changes include adding error interception capabilities, replacing conditional blocks with switch expressions for improved clarity, and refining method signatures and type annotations for better type safety.

Error Handling Enhancements:

  • Added an interceptError method to LoggerInterceptor for logging request, response, error, and stack trace details when an error occurs. (example/lib/common.dart, example/lib/common.dartR29-R50)
  • Introduced _interceptError in InterceptedClient to allow interceptors to handle errors during request execution. (lib/http/intercepted_client.dart, lib/http/intercepted_client.dartR351-R369)
  • Updated _attemptRequest in InterceptedClient to call _interceptError when an exception is caught, providing additional error context. (lib/http/intercepted_client.dart, lib/http/intercepted_client.dartR309-R314)

Refactoring with switch Expressions:

  • Replaced if-else blocks with switch expressions in BaseRequestCopyWith and BaseResponseCopyWith extensions to simplify logic and improve readability. (lib/extensions/base_request.dart, [1] [2]; lib/extensions/base_response_io.dart, [3] [4]; lib/extensions/base_response_none.dart, [5] [6]

Code Readability and Type Safety:

  • Added final keywords and refined type annotations across multiple files to enforce immutability and enhance clarity (e.g., MultipartRequest, Request, StreamedRequest). (lib/extensions/multipart_request.dart, [1]; lib/extensions/request.dart, [2]; lib/extensions/streamed_request.dart, [3]
  • Updated InterceptedClient to use late final for _inner and added type annotations for variables like response and message. (lib/http/intercepted_client.dart, [1] [2]

API Enhancements:

  • Added support for the OPTIONS HTTP method in the HttpMethod enum and refactored its fromString and asString methods to use switch expressions for consistency. (lib/http/http_methods.dart, lib/http/http_methods.dartL10-R32)

Simplifications and Optimizations:

  • Simplified the addParameters method in the Uri extension by using a concise functional approach with null-aware operators. (lib/extensions/uri.dart, lib/extensions/uri.dartL4-R16)

@stale
Copy link

stale bot commented Jul 19, 2025

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Jul 19, 2025
@techouse
Copy link
Contributor Author

@CodingAleCR I'll resolve all the merge conflicts in the evening. :)

@stale stale bot removed the wontfix This will not be worked on label Jul 22, 2025
techouse added 3 commits July 22, 2025 18:27
# Conflicts:
#	lib/extensions/uri.dart
#	lib/http/intercepted_client.dart
#	lib/models/interceptor_contract.dart
@techouse
Copy link
Contributor Author

techouse commented Jul 22, 2025

@CodingAleCR I've resolved all the merge conflicts. Please, check if something doens't make sense or needs more testing.

@td2thinh
Copy link
Contributor

Good job @techouse ✅ . So nice to see all these PRs getting merged finally. I've been taking a look at talker, looking too good to be true, I will need to persuade my devs to add it to in development flutter app 👍

@CodingAleCR
Copy link
Owner

I'll probably make a pre-release cut soon so it can be fully tried out before releasing. There's quite a few changes merging too, so I want to avoid disrupting anyone using the library.

@CodingAleCR CodingAleCR merged commit 2364df3 into CodingAleCR:main Jul 23, 2025
1 check passed
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