starlight36 / fetch-http-client

A http client wrapper for fetch api with middleware support.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request as fetch param

romanfazulianov opened this issue · comments

Hello, @starlight36

I'm looking forward for feature that supported by fetch, but as i see from source it is not possible with your library for now. I need to use previous Request instance with method fetch (retrying requests that was rejected by server in cases of status 502, for example)

https://developer.mozilla.org/en-US/docs/Web/API/Request#Examples

Please, say, do you see any way to do it using your library?

I think that you need an interceptor for retrying supported in our library ?

@romanfazulianov Hi, we can add a feature for retrying. Maybe,you only need some examples for writing interceptor ?

Hi! I figured out how to write an interceptor with desired behaivour, but as for me it's awkward.

I added callback retry into options param, and then in request interceptor i store it in a variable, delete its link from options and after that in response interceptor if (in my case) status of response is one of 502, 503, 504 - i push it to the queue. Than, after 10 seconds of waiting, i will retry all callbacks that stored in queue.

Retrying implemented with internals of your library should be helpful. I think it would be wounderful to configure retry timeout on new client instance creation and don't call response callback in then method when it has statuses from the defined list.

But if you have another opinion or suggestion, please let me know