From b59535530a05cceec3b8ce8bb516b0371cc02511 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 15 Feb 2023 22:24:28 -0800 Subject: [PATCH] added .Unwrap()error methods, and some error checking --- badgateway.go | 6 ++++++ badrequest.go | 4 ++++ conflict.go | 4 ++++ error.go | 1 + expectationfailed.go | 4 ++++ faileddependency.go | 3 +++ forbidden.go | 3 +++ gatewaytimeout.go | 6 ++++++ gone.go | 3 +++ httpversionnotsupported.go | 6 ++++++ insufficientstorage.go | 6 ++++++ internalservererror.go | 6 ++++++ lengthrequired.go | 3 +++ locked.go | 4 ++++ loopdetected.go | 6 ++++++ methodnotallowed.go | 3 +++ networkauthenticationrequired.go | 6 ++++++ notacceptable.go | 4 ++++ notextended.go | 6 ++++++ notfound.go | 4 ++++ notimplemented.go | 6 ++++++ payloadtoolarge.go | 4 ++++ paymentrequired.go | 4 ++++ preconditionfailed.go | 4 ++++ preconditionrequired.go | 3 +++ proxyauthrequired.go | 4 ++++ requestedrangenotsatisfiable.go | 4 ++++ requestentitytoolarge.go | 4 ++++ requestheaderfieldstoolarge.go | 4 ++++ requesttimeout.go | 4 ++++ requesturitoolong.go | 4 ++++ serviceunavailable.go | 4 ++++ teapot.go | 4 ++++ toomanyrequests.go | 4 ++++ unauthorized.go | 4 ++++ unavailableforlegalreasons.go | 3 +++ unprocessableentity.go | 4 ++++ unsupportedmediatype.go | 4 ++++ upgraderequired.go | 4 ++++ uritoolong.go | 4 ++++ variantaisonegotiates.go | 6 ++++++ 41 files changed, 174 insertions(+) diff --git a/badgateway.go b/badgateway.go index 4ba4168..93011fe 100644 --- a/badgateway.go +++ b/badgateway.go @@ -5,6 +5,8 @@ type BadGateway interface { BadGateway() } +var _ BadGateway = internalBadGateway{} + type internalBadGateway struct { err error } @@ -30,3 +32,7 @@ func (internalBadGateway) ServerError() { func (internalBadGateway) BadGateway() { // Nothing here. } + +func (receiver internalBadGateway) Unwrap() error { + return receiver.err +} diff --git a/badrequest.go b/badrequest.go index 2ce1816..5a37e6d 100644 --- a/badrequest.go +++ b/badrequest.go @@ -30,3 +30,7 @@ func (internalBadRequest) ClientError() { func (internalBadRequest) BadRequest() { // Nothing here. } + +func (receiver internalBadRequest) Unwrap() error { + return receiver.err +} diff --git a/conflict.go b/conflict.go index a2945c6..6a544da 100644 --- a/conflict.go +++ b/conflict.go @@ -30,3 +30,7 @@ func (internalConflict) ClientError() { func (internalConflict) Conflict() { // Nothing here. } + +func (receiver internalConflict) Unwrap() error { + return receiver.err +} diff --git a/error.go b/error.go index 1848abb..17b99a0 100644 --- a/error.go +++ b/error.go @@ -3,4 +3,5 @@ package errhttp type Error interface { error Err() error + Unwrap() error } diff --git a/expectationfailed.go b/expectationfailed.go index 6a77270..feb518a 100644 --- a/expectationfailed.go +++ b/expectationfailed.go @@ -30,3 +30,7 @@ func (internalExpectationFailed) ClientError() { func (internalExpectationFailed) ExpectationFailed() { // Nothing here. } + +func (receiver internalExpectationFailed) Unwrap() error { + return receiver.err +} diff --git a/faileddependency.go b/faileddependency.go index 5992003..5ef5e91 100644 --- a/faileddependency.go +++ b/faileddependency.go @@ -31,3 +31,6 @@ func (internalFailedDependency) FailedDependency() { // Nothing here. } +func (receiver internalFailedDependency) Unwrap() error { + return receiver.err +} diff --git a/forbidden.go b/forbidden.go index 783204a..89c0627 100644 --- a/forbidden.go +++ b/forbidden.go @@ -31,3 +31,6 @@ func (internalForbidden) Forbidden() { // Nothing here. } +func (receiver internalForbidden) Unwrap() error { + return receiver.err +} diff --git a/gatewaytimeout.go b/gatewaytimeout.go index 5b3eac4..a69cd60 100644 --- a/gatewaytimeout.go +++ b/gatewaytimeout.go @@ -5,6 +5,8 @@ type GatewayTimeout interface { GatewayTimeout() } +var _ GatewayTimeout = internalGatewayTimeout{} + type internalGatewayTimeout struct { err error } @@ -30,3 +32,7 @@ func (internalGatewayTimeout) ServerError() { func (internalGatewayTimeout) GatewayTimeout() { // Nothing here. } + +func (receiver internalGatewayTimeout) Unwrap() error { + return receiver.err +} diff --git a/gone.go b/gone.go index 19e88fc..a2cd6ed 100644 --- a/gone.go +++ b/gone.go @@ -31,3 +31,6 @@ func (internalGone) Gone() { // Nothing here. } +func (receiver internalGone) Unwrap() error { + return receiver.err +} diff --git a/httpversionnotsupported.go b/httpversionnotsupported.go index f066b98..cf8a82d 100644 --- a/httpversionnotsupported.go +++ b/httpversionnotsupported.go @@ -5,6 +5,8 @@ type HTTPVersionNotSupported interface { HTTPVersionNotSupported() } +var _ HTTPVersionNotSupported = internalHTTPVersionNotSupported{} + type internalHTTPVersionNotSupported struct { err error } @@ -30,3 +32,7 @@ func (internalHTTPVersionNotSupported) ServerError() { func (internalHTTPVersionNotSupported) HTTPVersionNotSupported() { // Nothing here. } + +func (receiver internalHTTPVersionNotSupported) Unwrap() error { + return receiver.err +} diff --git a/insufficientstorage.go b/insufficientstorage.go index 436cf88..b897c8b 100644 --- a/insufficientstorage.go +++ b/insufficientstorage.go @@ -5,6 +5,8 @@ type InsufficientStorage interface { InsufficientStorage() } +var _ InsufficientStorage = internalInsufficientStorage{} + type internalInsufficientStorage struct { err error } @@ -30,3 +32,7 @@ func (internalInsufficientStorage) ServerError() { func (internalInsufficientStorage) InsufficientStorage() { // Nothing here. } + +func (receiver internalInsufficientStorage) Unwrap() error { + return receiver.err +} diff --git a/internalservererror.go b/internalservererror.go index c270829..1679dd6 100644 --- a/internalservererror.go +++ b/internalservererror.go @@ -5,6 +5,8 @@ type InternalServerError interface { InternalServerError() } +var _ InternalServerError = internalInternalServerError{} + type internalInternalServerError struct { err error } @@ -30,3 +32,7 @@ func (internalInternalServerError) ServerError() { func (internalInternalServerError) InternalServerError() { // Nothing here. } + +func (receiver internalInternalServerError) Unwrap() error { + return receiver.err +} diff --git a/lengthrequired.go b/lengthrequired.go index 6dae353..4352f91 100644 --- a/lengthrequired.go +++ b/lengthrequired.go @@ -31,3 +31,6 @@ func (internalLengthRequired) LengthRequired() { // Nothing here. } +func (receiver internalLengthRequired) Unwrap() error { + return receiver.err +} diff --git a/locked.go b/locked.go index 8b7750c..5fd8590 100644 --- a/locked.go +++ b/locked.go @@ -30,3 +30,7 @@ func (internalLocked) ClientError() { func (internalLocked) Locked() { // Nothing here. } + +func (receiver internalLocked) Unwrap() error { + return receiver.err +} diff --git a/loopdetected.go b/loopdetected.go index fe79ee4..0414dc3 100644 --- a/loopdetected.go +++ b/loopdetected.go @@ -5,6 +5,8 @@ type LoopDetected interface { LoopDetected() } +var _ LoopDetected = internalLoopDetected{} + type internalLoopDetected struct { err error } @@ -30,3 +32,7 @@ func (internalLoopDetected) ServerError() { func (internalLoopDetected) LoopDetected() { // Nothing here. } + +func (receiver internalLoopDetected) Unwrap() error { + return receiver.err +} diff --git a/methodnotallowed.go b/methodnotallowed.go index 01fce93..0e41bd3 100644 --- a/methodnotallowed.go +++ b/methodnotallowed.go @@ -31,3 +31,6 @@ func (internalMethodNotAllowed) MethodNotAllowed() { // Nothing here. } +func (receiver internalMethodNotAllowed) Unwrap() error { + return receiver.err +} diff --git a/networkauthenticationrequired.go b/networkauthenticationrequired.go index 56a83f6..e130c55 100644 --- a/networkauthenticationrequired.go +++ b/networkauthenticationrequired.go @@ -5,6 +5,8 @@ type NetworkAuthenticationRequired interface { NetworkAuthenticationRequired() } +var _ NetworkAuthenticationRequired = internalNetworkAuthenticationRequired{} + type internalNetworkAuthenticationRequired struct { err error } @@ -30,3 +32,7 @@ func (internalNetworkAuthenticationRequired) ServerError() { func (internalNetworkAuthenticationRequired) NetworkAuthenticationRequired() { // Nothing here. } + +func (receiver internalNetworkAuthenticationRequired) Unwrap() error { + return receiver.err +} diff --git a/notacceptable.go b/notacceptable.go index 84fcb67..f570d87 100644 --- a/notacceptable.go +++ b/notacceptable.go @@ -30,3 +30,7 @@ func (internalNotAcceptable) ClientError() { func (internalNotAcceptable) NotAcceptable() { // Nothing here. } + +func (receiver internalNotAcceptable) Unwrap() error { + return receiver.err +} diff --git a/notextended.go b/notextended.go index 7ea9412..14abc96 100644 --- a/notextended.go +++ b/notextended.go @@ -5,6 +5,8 @@ type NotExtended interface { NotExtended() } +var _ NotExtended = internalNotExtended{} + type internalNotExtended struct { err error } @@ -30,3 +32,7 @@ func (internalNotExtended) ServerError() { func (internalNotExtended) NotExtended() { // Nothing here. } + +func (receiver internalNotExtended) Unwrap() error { + return receiver.err +} diff --git a/notfound.go b/notfound.go index 4a1182d..f4a8d2f 100644 --- a/notfound.go +++ b/notfound.go @@ -30,3 +30,7 @@ func (internalNotFound ) ClientError() { func (internalNotFound ) NotFound() { // Nothing here. } + +func (receiver internalNotFound) Unwrap() error { + return receiver.err +} diff --git a/notimplemented.go b/notimplemented.go index 90e931c..f8808ec 100644 --- a/notimplemented.go +++ b/notimplemented.go @@ -5,6 +5,8 @@ type NotImplemented interface { NotImplemented() } +var _ NotImplemented = internalNotImplemented{} + type internalNotImplemented struct { err error } @@ -30,3 +32,7 @@ func (internalNotImplemented) ServerError() { func (internalNotImplemented) NotImplemented() { // Nothing here. } + +func (receiver internalNotImplemented) Unwrap() error { + return receiver.err +} diff --git a/payloadtoolarge.go b/payloadtoolarge.go index 6204cfb..dd10227 100644 --- a/payloadtoolarge.go +++ b/payloadtoolarge.go @@ -30,3 +30,7 @@ func (internalPayloadTooLarge) ClientError() { func (internalPayloadTooLarge) PayloadTooLarge() { // Nothing here. } + +func (receiver internalPayloadTooLarge) Unwrap() error { + return receiver.err +} diff --git a/paymentrequired.go b/paymentrequired.go index e0f9788..c3bee0c 100644 --- a/paymentrequired.go +++ b/paymentrequired.go @@ -30,3 +30,7 @@ func (internalPaymentRequired) ClientError() { func (internalPaymentRequired) PaymentRequired() { // Nothing here. } + +func (receiver internalPaymentRequired) Unwrap() error { + return receiver.err +} diff --git a/preconditionfailed.go b/preconditionfailed.go index 526919a..fc41de9 100644 --- a/preconditionfailed.go +++ b/preconditionfailed.go @@ -30,3 +30,7 @@ func (internalPreconditionFailed) ClientError() { func (internalPreconditionFailed) PreconditionFailed() { // Nothing here. } + +func (receiver internalPreconditionFailed) Unwrap() error { + return receiver.err +} diff --git a/preconditionrequired.go b/preconditionrequired.go index 3d1a960..d25477e 100644 --- a/preconditionrequired.go +++ b/preconditionrequired.go @@ -31,3 +31,6 @@ func (internalPreconditionRequired) PreconditionRequired() { // Nothing here. } +func (receiver internalPreconditionRequired) Unwrap() error { + return receiver.err +} diff --git a/proxyauthrequired.go b/proxyauthrequired.go index 19fb288..a386b02 100644 --- a/proxyauthrequired.go +++ b/proxyauthrequired.go @@ -30,3 +30,7 @@ func (internalProxyAuthRequired) ClientError() { func (internalProxyAuthRequired) ProxyAuthRequired() { // Nothing here. } + +func (receiver internalProxyAuthRequired) Unwrap() error { + return receiver.err +} diff --git a/requestedrangenotsatisfiable.go b/requestedrangenotsatisfiable.go index f0197ba..77d0bfc 100644 --- a/requestedrangenotsatisfiable.go +++ b/requestedrangenotsatisfiable.go @@ -30,3 +30,7 @@ func (internalRequestedRangeNotSatisfiable) ClientError() { func (internalRequestedRangeNotSatisfiable) RequestedRangeNotSatisfiable() { // Nothing here. } + +func (receiver internalRequestedRangeNotSatisfiable) Unwrap() error { + return receiver.err +} diff --git a/requestentitytoolarge.go b/requestentitytoolarge.go index 3086eda..ce45ef5 100644 --- a/requestentitytoolarge.go +++ b/requestentitytoolarge.go @@ -30,3 +30,7 @@ func (internalRequestEntityTooLarge) ClientError() { func (internalRequestEntityTooLarge) RequestEntityTooLarge() { // Nothing here. } + +func (receiver internalRequestEntityTooLarge) Unwrap() error { + return receiver.err +} diff --git a/requestheaderfieldstoolarge.go b/requestheaderfieldstoolarge.go index 3f64848..5dbac17 100644 --- a/requestheaderfieldstoolarge.go +++ b/requestheaderfieldstoolarge.go @@ -31,3 +31,7 @@ func (internalRequestHeaderFieldsTooLarge) ClientError() { func (internalRequestHeaderFieldsTooLarge) RequestHeaderFieldsTooLarge() { // Nothing here. } + +func (receiver internalRequestHeaderFieldsTooLarge) Unwrap() error { + return receiver.err +} diff --git a/requesttimeout.go b/requesttimeout.go index 5b1be9f..ec7f4de 100644 --- a/requesttimeout.go +++ b/requesttimeout.go @@ -31,3 +31,7 @@ func (internalRequestTimeout) ClientError() { func (internalRequestTimeout) RequestTimeout() { // Nothing here. } + +func (receiver internalRequestTimeout) Unwrap() error { + return receiver.err +} diff --git a/requesturitoolong.go b/requesturitoolong.go index 53be12a..92e1185 100644 --- a/requesturitoolong.go +++ b/requesturitoolong.go @@ -31,3 +31,7 @@ func (internalRequestURITooLong) ClientError() { func (internalRequestURITooLong) RequestURITooLong() { // Nothing here. } + +func (receiver internalRequestURITooLong) Unwrap() error { + return receiver.err +} diff --git a/serviceunavailable.go b/serviceunavailable.go index fefd683..3db931f 100644 --- a/serviceunavailable.go +++ b/serviceunavailable.go @@ -30,3 +30,7 @@ func (internalServiceUnavailable) ServerError() { func (internalServiceUnavailable) ServiceUnavailable() { // Nothing here. } + +func (receiver internalServiceUnavailable) Unwrap() error { + return receiver.err +} diff --git a/teapot.go b/teapot.go index b1fd56c..252c7a4 100644 --- a/teapot.go +++ b/teapot.go @@ -30,3 +30,7 @@ func (internalTeapot) ClientError() { func (internalTeapot) Teapot() { // Nothing here. } + +func (receiver internalTeapot) Unwrap() error { + return receiver.err +} diff --git a/toomanyrequests.go b/toomanyrequests.go index 9b19ffa..0e54082 100644 --- a/toomanyrequests.go +++ b/toomanyrequests.go @@ -30,3 +30,7 @@ func (internalTooManyRequests) ClientError() { func (internalTooManyRequests) TooManyRequests() { // Nothing here. } + +func (receiver internalTooManyRequests) Unwrap() error { + return receiver.err +} diff --git a/unauthorized.go b/unauthorized.go index f0a60ea..67e3e87 100644 --- a/unauthorized.go +++ b/unauthorized.go @@ -30,3 +30,7 @@ func (internalUnauthorized) ClientError() { func (internalUnauthorized) Unauthorized() { // Nothing here. } + +func (receiver internalUnauthorized) Unwrap() error { + return receiver.err +} diff --git a/unavailableforlegalreasons.go b/unavailableforlegalreasons.go index ef24aab..3cef643 100644 --- a/unavailableforlegalreasons.go +++ b/unavailableforlegalreasons.go @@ -31,3 +31,6 @@ func (internalUnavailableForLegalReasons) UnavailableForLegalReasons() { // Nothing here. } +func (receiver internalUnavailableForLegalReasons) Unwrap() error { + return receiver.err +} diff --git a/unprocessableentity.go b/unprocessableentity.go index 1dde935..65c9d06 100644 --- a/unprocessableentity.go +++ b/unprocessableentity.go @@ -30,3 +30,7 @@ func (internalUnprocessableEntity) ClientError() { func (internalUnprocessableEntity) UnprocessableEntity() { // Nothing here. } + +func (receiver internalUnprocessableEntity) Unwrap() error { + return receiver.err +} diff --git a/unsupportedmediatype.go b/unsupportedmediatype.go index 1030c53..160eb88 100644 --- a/unsupportedmediatype.go +++ b/unsupportedmediatype.go @@ -30,3 +30,7 @@ func (internalUnsupportedMediaType) ClientError() { func (internalUnsupportedMediaType) UnsupportedMediaType() { // Nothing here. } + +func (receiver internalUnsupportedMediaType) Unwrap() error { + return receiver.err +} diff --git a/upgraderequired.go b/upgraderequired.go index f4e3e5e..0694a6c 100644 --- a/upgraderequired.go +++ b/upgraderequired.go @@ -30,3 +30,7 @@ func (internalUpgradeRequired) ClientError() { func (internalUpgradeRequired) UpgradeRequired() { // Nothing here. } + +func (receiver internalUpgradeRequired) Unwrap() error { + return receiver.err +} diff --git a/uritoolong.go b/uritoolong.go index b0025eb..95a7935 100644 --- a/uritoolong.go +++ b/uritoolong.go @@ -30,3 +30,7 @@ func (internalURITooLong) ClientError() { func (internalURITooLong) URITooLong() { // Nothing here. } + +func (receiver internalURITooLong) Unwrap() error { + return receiver.err +} diff --git a/variantaisonegotiates.go b/variantaisonegotiates.go index 56e75a3..1e9599c 100644 --- a/variantaisonegotiates.go +++ b/variantaisonegotiates.go @@ -5,6 +5,8 @@ type VariantAlsoNegotiates interface { VariantAlsoNegotiates() } +var _ VariantAlsoNegotiates = internalVariantAlsoNegotiates{} + type internalVariantAlsoNegotiates struct { err error } @@ -30,3 +32,7 @@ func (internalVariantAlsoNegotiates) ServerError() { func (internalVariantAlsoNegotiates) VariantAlsoNegotiates() { // Nothing here. } + +func (receiver internalVariantAlsoNegotiates) Unwrap() error { + return receiver.err +}