CodingAleCR / http_interceptor

A lightweight, simple plugin that allows you to intercept request and response objects and modify them if desired.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Adding the possibility to add a generic request timeout handler

javiermrz opened this issue · comments

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()
)

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 🙌🏼

I'll do a PR no problem!

Here you go 🥳 #108

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