Infisical / infisical-node

♾ Official Infisical SDK for Node
https://infisical.com
MIT License
68 stars 19 forks source link

Only GET request should be cached and improve error handling #9

Open sebastianwessel opened 1 year ago

sebastianwessel commented 1 year ago

It makes no sense to return cached responses for request of creating, updating or removing secrets if they are not successfully. I would expect, that these methods are throwing or that they are returning some (full) error object. In any case, when an action is failing, the information is lost and data is not changed as expected.

Currently, you need to do something like this:

const result = await this.client.updateSecret(secretName, configValue)
if (result.isFallback) {
   throw new Error('Unable to update secret for unknown reason')
}

Also, as always some result is returned, errors are swallowed and not visible to the consumer. At least in the returned ISecretBundle, there should be some optional error field, which contains the error.

Something like this:

const result = await this.client.updateSecret(secretName, configValue)
if (result.error) {
   console.error(result.error)
   throw new Error('Unable to update secret: ' + result.error.message )
}