From aea41574dfef57c350347e5eb9774a7954f3ed8a Mon Sep 17 00:00:00 2001 From: Soulou Date: Mon, 20 Jan 2025 11:33:58 +0100 Subject: [PATCH] [STORY-1378] Allow getting internal data of nsqconsumer.Error for better testability --- nsqconsumer/CHANGELOG.md | 3 +++ nsqconsumer/consumer.go | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/nsqconsumer/CHANGELOG.md b/nsqconsumer/CHANGELOG.md index 92f0466c..fd880bc8 100644 --- a/nsqconsumer/CHANGELOG.md +++ b/nsqconsumer/CHANGELOG.md @@ -2,6 +2,9 @@ ## To be Released +* feat: nsqconsumer.Error - `Unwrap` method to be compatible with `errors.Is/As()` +* feat: nsqconsumer.Error - `NoRetry` to get if the message should be retried or not to be consumed. + ## v1.3.1 * fix: Use API for github.com/go-utils/logger instead of setting logger manually in context diff --git a/nsqconsumer/consumer.go b/nsqconsumer/consumer.go index 803cf88c..cc0b41bb 100644 --- a/nsqconsumer/consumer.go +++ b/nsqconsumer/consumer.go @@ -83,6 +83,16 @@ func (nsqerr Error) Error() string { return nsqerr.error.Error() } +// Unwrap returns the cause of the error to be compatible with errors.As/Is() +func (nsqerr Error) Unwrap() error { + return nsqerr.error +} + +// NoRetry returns true if the message should not be retried to be handled +func (nsqerr Error) NoRetry() bool { + return nsqerr.noRetry +} + type ErrorOpts struct { NoRetry bool }