diff --git a/internals/errio/errors.go b/internals/errio/errors.go index ea490e0b..77b348b1 100644 --- a/internals/errio/errors.go +++ b/internals/errio/errors.go @@ -158,6 +158,7 @@ func UnexpectedError(err error) PublicError { "an unexpected error occurred: %v\n\nTry again later or contact support@secrethub.io if the problem persists", err, ), + err: err, } } @@ -190,6 +191,7 @@ type PublicError struct { Namespace Namespace `json:"namespace,omitempty"` Code string `json:"code"` Message string `json:"message"` + err error } // PublicError implements the error interface. @@ -221,6 +223,11 @@ func (e PublicError) Type() string { return fmt.Sprintf("%s.%s", e.Namespace, e.Code) } +// Unwrap returns the wrapped error if the PublicError represents an error wrapped as an UnexpectedError. +func (e PublicError) Unwrap() error { + return e.err +} + // PublicStatusError represents an http error. It contains an HTTP status // code and can be json encoded in an HTTP response. type PublicStatusError struct {