Unleash / unleash-client-node

Unleash client SDK for Node.js
https://docs.getunleash.io
Apache License 2.0
207 stars 71 forks source link

Clean backup on 401 http status code #642

Open jojovem opened 3 weeks ago

jojovem commented 3 weeks ago

Describe the feature request

Hi all!

Does it make sense to pass to the StoreProvider a callback that runs on every request with the status code response? The idea is to clean the backup as soon as we get a 401 response from unleash.

Knowing that the request was forbidden, i think it makes sense to clean it.

What are your thoughts on this?

Thank you!

Background

We had some problems while migrating our unleash between two kubernetes clusters. We didnt understand at first, why even after the api token was changed, the requestes from unleash-client-node were still passing.

We figured out that the backup was returning the responses.

Although the backup is a great feature for resilience, for us, it didnt make much sense to use the backup even after a 401 response.

Solution suggestions

Inject a request callback into the StoreProvider that can monitor the requests and take action depending on the response, so developers could provide a functionality to clean the backup depending on the status code.

Although it seems this could be a nice feature for the default storage provider.

chriswk commented 3 weeks ago

Hi @jojovem - Would you be willing to write a PR implementing this yourself? I think your idea makes sense, but we don't have any free engineers to implement this at the moment

kwasniew commented 3 weeks ago

@jojovem I'm wondering if you can compose the behavior you're describing using existing building blocks.

Pseudocode below:

const appName = 'my-app';
const storageProvider = new FileStorageProvider();
const unleash = new Unleash({storageProvider, appName});
unleash.on('error', (e) => {
  if(/* check error */) {
    storageProvider.set('my-app', []);
  }
});