Add APIErrorWrapper so that underlying errors can be logged (#1246)

This commit is contained in:
Owen Strain
2018-09-28 17:26:54 -07:00
committed by GitHub
parent 0dd24932f2
commit 21f77f837e
4 changed files with 48 additions and 10 deletions

View File

@@ -194,3 +194,26 @@ type ErrorWrapper struct {
func (m *ErrorWrapper) Validate() error {
return nil
}
// APIErrorWrapper wraps an error with an APIError such that the APIError
// governs the HTTP response but the root error remains accessible.
type APIErrorWrapper interface {
APIError
RootError() error
}
type apiErrorWrapper struct {
APIError
root error
}
func (w apiErrorWrapper) RootError() error {
return w.root
}
func NewAPIErrorWrapper(apiErr APIError, rootErr error) APIErrorWrapper {
return &apiErrorWrapper{
APIError: apiErr,
root: rootErr,
}
}