Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #226 from secrethub/feature/unwrap-unexpected-err
Browse files Browse the repository at this point in the history
 Allow UnexpectedError to be unwrapped to wapped error
  • Loading branch information
SimonBarendse authored Jan 5, 2021
2 parents 7c05f14 + 309a63b commit a8ac464
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions internals/errio/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a8ac464

Please sign in to comment.