-
Notifications
You must be signed in to change notification settings - Fork 5
Don't return cached errors, allow to retry #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
packages/core/src/idempotency.ts
Outdated
| IdempotencyErrorCodes.IDEMPOTENCY_FINGERPRINT_MISSMATCH, | ||
| ); | ||
| } | ||
| if (data.response?.error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work—thanks for the PR!
This change isn’t backward-compatible as-is. Could we add a new configuration option to control whether errors get cached? If unset, it would default to the existing behavior.
When the new config is enabled, it makes sense not to cache the error itself. In that case, we should clear the cache key and allow subsequent requests to retry—this aligns with the intended behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added config and ability to delete cache. Let's see what else can be improved :)
5bf4dcb to
d69b799
Compare
mahendraHegde
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, added few comments
| return val ?? undefined; | ||
| } | ||
|
|
||
| async delete(key: string): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to go inside postgres adapter too, if you are not familiar with postgres, no worries i can take care of it too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good thing is that Postgres adapter already has this :)
https://github.com/mahendraHegde/node-idempotency/blob/main/packages/storage-adapter-postgres/src/adapter-postgres.ts#L108
| return response; | ||
| }), | ||
| catchError((err) => { | ||
| if (idempotencyReq.options?.skipErrorsCache) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why handle it only for nestJS? why not add this logic inside the core(packages/core/src/idempotency.ts)->onResponse so that every adapter will get the feature out of the box?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great point, and code get so much simpler. Updated, please review.
|
|
||
| if (res.error && req.options?.skipErrorsCache) { | ||
| // do not cache the error itself, clear the cache key and allow subsequent requests to retry | ||
| await this.storage.delete(cacheKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did you miss a return statement here? because the set below will set the response anyway.
https://github.com/mahendraHegde/node-idempotency/pull/36/files#diff-3c306f162d9ea758a7d4323df8bfe9476e1a263a7138ea8e22e531e30152b8fdR177-R184
also would you mind adding some tests like we have for other cases so that we could catch bugs like this early(I'd appreciate it if you could add tests for adapters too, if not i can add them too)?
Hi!
Thanks for awesome module 👍 When doing tests I bumped into an issue, the module would cache this error.
Examples:
Even after error reason is gone (database is up, source code updated), this module will keep returning old cached error without ability to fix this.
Please review :)