Skip to content

Conversation

@unicoder88
Copy link
Contributor

Hi!

Thanks for awesome module 👍 When doing tests I bumped into an issue, the module would cache this error.

Examples:

  • database was down when trying to save something, and 5xx error was returned
  • syntax error - trying to access non-existing JSON body member without checking properly

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

IdempotencyErrorCodes.IDEMPOTENCY_FINGERPRINT_MISSMATCH,
);
}
if (data.response?.error) {
Copy link
Owner

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.

Copy link
Contributor Author

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

Copy link
Owner

@mahendraHegde mahendraHegde left a 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> {
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return response;
}),
catchError((err) => {
if (idempotencyReq.options?.skipErrorsCache) {
Copy link
Owner

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?

Copy link
Contributor Author

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);
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants