CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.
MIT License
133 stars 67 forks source link

Adding the possibility to add a generic request timeout handler #107

Closed javiermrz closed 2 years ago

javiermrz commented 2 years ago

First of all, thanks for this great library, really great work!

Is your feature request related to a problem? Please describe. I find it weird that there is a request timeout option, which will throw an error, but there is not an option to handle that error (to be able to, for example, show a toast with a generic error text if the timeout throws).

Describe the solution you'd like The solution is actually really easy and it only requires a couple lines. In intercepted_client.dart, in line 242 you have this:

await send(interceptedRequest).timeout(requestTimeout!);

Dart lets you override a Future timeout behaviour by adding a parameter:

await send(interceptedRequest).timeout(requestTimeout!, onTimeout: _onTimeout);

and then you would only have to accept this new parameter in the build method:

InterceptedClient.build(
  ...
  requestTimeout: Duration(seconds:20),
  onRequestTimeout: Function()
)
CodingAleCR commented 2 years ago

Hey, thank you for your proposal, it makes sense to add it and simple enough.🥳

I will try to get it soon, but contributions are always welcomed 🙌🏼

javiermrz commented 2 years ago

I'll do a PR no problem!

javiermrz commented 2 years ago

Here you go 🥳 https://github.com/CodingAleCR/http_interceptor/pull/108

CodingAleCR commented 2 years ago

The PR has been accepted and this should be up on 2.0.0-beta.5