From 1b349fbb2166d0f6f1d908c10f50d527402414c4 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Mon, 6 Feb 2017 13:14:15 -0800 Subject: [PATCH] server error --- badgateway.go | 32 ++++++++++++++++++++++++++++++++ gatewaytimeout.go | 32 ++++++++++++++++++++++++++++++++ httpversionnotsupported.go | 32 ++++++++++++++++++++++++++++++++ insufficientstorage.go | 32 ++++++++++++++++++++++++++++++++ internalservererror.go | 32 ++++++++++++++++++++++++++++++++ loopdetected.go | 32 ++++++++++++++++++++++++++++++++ networkauthenticationrequired.go | 32 ++++++++++++++++++++++++++++++++ notextended.go | 32 ++++++++++++++++++++++++++++++++ notimplemented.go | 32 ++++++++++++++++++++++++++++++++ servererror_test.go | 26 ++++++++++++++++++++++++++ serviceunavailable.go | 32 ++++++++++++++++++++++++++++++++ variantaisonegotiates.go | 32 ++++++++++++++++++++++++++++++++ 12 files changed, 378 insertions(+) create mode 100644 badgateway.go create mode 100644 gatewaytimeout.go create mode 100644 httpversionnotsupported.go create mode 100644 insufficientstorage.go create mode 100644 internalservererror.go create mode 100644 loopdetected.go create mode 100644 networkauthenticationrequired.go create mode 100644 notextended.go create mode 100644 notimplemented.go create mode 100644 servererror_test.go create mode 100644 serviceunavailable.go create mode 100644 variantaisonegotiates.go diff --git a/badgateway.go b/badgateway.go new file mode 100644 index 0000000..4ba4168 --- /dev/null +++ b/badgateway.go @@ -0,0 +1,32 @@ +package errhttp + +type BadGateway interface { + ServerError + BadGateway() +} + +type internalBadGateway struct { + err error +} + +func BadGatewayWrap(err error) error { + return internalBadGateway{ + err:err, + } +} + +func (receiver internalBadGateway) Error() string { + return receiver.err.Error() +} + +func (receiver internalBadGateway) Err() error { + return receiver.err +} + +func (internalBadGateway) ServerError() { + // Nothing here. +} + +func (internalBadGateway) BadGateway() { + // Nothing here. +} diff --git a/gatewaytimeout.go b/gatewaytimeout.go new file mode 100644 index 0000000..5b3eac4 --- /dev/null +++ b/gatewaytimeout.go @@ -0,0 +1,32 @@ +package errhttp + +type GatewayTimeout interface { + ServerError + GatewayTimeout() +} + +type internalGatewayTimeout struct { + err error +} + +func GatewayTimeoutWrap(err error) error { + return internalGatewayTimeout{ + err:err, + } +} + +func (receiver internalGatewayTimeout) Error() string { + return receiver.err.Error() +} + +func (receiver internalGatewayTimeout) Err() error { + return receiver.err +} + +func (internalGatewayTimeout) ServerError() { + // Nothing here. +} + +func (internalGatewayTimeout) GatewayTimeout() { + // Nothing here. +} diff --git a/httpversionnotsupported.go b/httpversionnotsupported.go new file mode 100644 index 0000000..f066b98 --- /dev/null +++ b/httpversionnotsupported.go @@ -0,0 +1,32 @@ +package errhttp + +type HTTPVersionNotSupported interface { + ServerError + HTTPVersionNotSupported() +} + +type internalHTTPVersionNotSupported struct { + err error +} + +func HTTPVersionNotSupportedWrap(err error) error { + return internalHTTPVersionNotSupported{ + err:err, + } +} + +func (receiver internalHTTPVersionNotSupported) Error() string { + return receiver.err.Error() +} + +func (receiver internalHTTPVersionNotSupported) Err() error { + return receiver.err +} + +func (internalHTTPVersionNotSupported) ServerError() { + // Nothing here. +} + +func (internalHTTPVersionNotSupported) HTTPVersionNotSupported() { + // Nothing here. +} diff --git a/insufficientstorage.go b/insufficientstorage.go new file mode 100644 index 0000000..436cf88 --- /dev/null +++ b/insufficientstorage.go @@ -0,0 +1,32 @@ +package errhttp + +type InsufficientStorage interface { + ServerError + InsufficientStorage() +} + +type internalInsufficientStorage struct { + err error +} + +func InsufficientStorageWrap(err error) error { + return internalInsufficientStorage{ + err:err, + } +} + +func (receiver internalInsufficientStorage) Error() string { + return receiver.err.Error() +} + +func (receiver internalInsufficientStorage) Err() error { + return receiver.err +} + +func (internalInsufficientStorage) ServerError() { + // Nothing here. +} + +func (internalInsufficientStorage) InsufficientStorage() { + // Nothing here. +} diff --git a/internalservererror.go b/internalservererror.go new file mode 100644 index 0000000..c270829 --- /dev/null +++ b/internalservererror.go @@ -0,0 +1,32 @@ +package errhttp + +type InternalServerError interface { + ServerError + InternalServerError() +} + +type internalInternalServerError struct { + err error +} + +func InternalServerErrorWrap(err error) error { + return internalInternalServerError{ + err:err, + } +} + +func (receiver internalInternalServerError) Error() string { + return receiver.err.Error() +} + +func (receiver internalInternalServerError) Err() error { + return receiver.err +} + +func (internalInternalServerError) ServerError() { + // Nothing here. +} + +func (internalInternalServerError) InternalServerError() { + // Nothing here. +} diff --git a/loopdetected.go b/loopdetected.go new file mode 100644 index 0000000..fe79ee4 --- /dev/null +++ b/loopdetected.go @@ -0,0 +1,32 @@ +package errhttp + +type LoopDetected interface { + ServerError + LoopDetected() +} + +type internalLoopDetected struct { + err error +} + +func LoopDetectedWrap(err error) error { + return internalLoopDetected{ + err:err, + } +} + +func (receiver internalLoopDetected) Error() string { + return receiver.err.Error() +} + +func (receiver internalLoopDetected) Err() error { + return receiver.err +} + +func (internalLoopDetected) ServerError() { + // Nothing here. +} + +func (internalLoopDetected) LoopDetected() { + // Nothing here. +} diff --git a/networkauthenticationrequired.go b/networkauthenticationrequired.go new file mode 100644 index 0000000..56a83f6 --- /dev/null +++ b/networkauthenticationrequired.go @@ -0,0 +1,32 @@ +package errhttp + +type NetworkAuthenticationRequired interface { + ServerError + NetworkAuthenticationRequired() +} + +type internalNetworkAuthenticationRequired struct { + err error +} + +func NetworkAuthenticationRequiredWrap(err error) error { + return internalNetworkAuthenticationRequired{ + err:err, + } +} + +func (receiver internalNetworkAuthenticationRequired) Error() string { + return receiver.err.Error() +} + +func (receiver internalNetworkAuthenticationRequired) Err() error { + return receiver.err +} + +func (internalNetworkAuthenticationRequired) ServerError() { + // Nothing here. +} + +func (internalNetworkAuthenticationRequired) NetworkAuthenticationRequired() { + // Nothing here. +} diff --git a/notextended.go b/notextended.go new file mode 100644 index 0000000..7ea9412 --- /dev/null +++ b/notextended.go @@ -0,0 +1,32 @@ +package errhttp + +type NotExtended interface { + ServerError + NotExtended() +} + +type internalNotExtended struct { + err error +} + +func NotExtendedWrap(err error) error { + return internalNotExtended{ + err:err, + } +} + +func (receiver internalNotExtended) Error() string { + return receiver.err.Error() +} + +func (receiver internalNotExtended) Err() error { + return receiver.err +} + +func (internalNotExtended) ServerError() { + // Nothing here. +} + +func (internalNotExtended) NotExtended() { + // Nothing here. +} diff --git a/notimplemented.go b/notimplemented.go new file mode 100644 index 0000000..90e931c --- /dev/null +++ b/notimplemented.go @@ -0,0 +1,32 @@ +package errhttp + +type NotImplemented interface { + ServerError + NotImplemented() +} + +type internalNotImplemented struct { + err error +} + +func NotImplementedWrap(err error) error { + return internalNotImplemented{ + err:err, + } +} + +func (receiver internalNotImplemented) Error() string { + return receiver.err.Error() +} + +func (receiver internalNotImplemented) Err() error { + return receiver.err +} + +func (internalNotImplemented) ServerError() { + // Nothing here. +} + +func (internalNotImplemented) NotImplemented() { + // Nothing here. +} diff --git a/servererror_test.go b/servererror_test.go new file mode 100644 index 0000000..237a40a --- /dev/null +++ b/servererror_test.go @@ -0,0 +1,26 @@ +package errhttp + +import ( + "testing" +) + +func TestServerError(t *testing.T) { + + var x ServerError + + x = internalInternalServerError{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalNotImplemented{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalBadGateway{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalServiceUnavailable{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalGatewayTimeout{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalHTTPVersionNotSupported{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalVariantAlsoNegotiates{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalInsufficientStorage{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalLoopDetected{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalNotExtended{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + x = internalNetworkAuthenticationRequired{} // THESE ARE THE LINE THAT ACTUALLY MATTERS IN THIS TEST. + + if nil == x { + t.Errorf("This should never happen.") + } +} diff --git a/serviceunavailable.go b/serviceunavailable.go new file mode 100644 index 0000000..fefd683 --- /dev/null +++ b/serviceunavailable.go @@ -0,0 +1,32 @@ +package errhttp + +type ServiceUnavailable interface { + ServerError + ServiceUnavailable() +} + +type internalServiceUnavailable struct { + err error +} + +func ServiceUnavailableWrap(err error) error { + return internalServiceUnavailable{ + err:err, + } +} + +func (receiver internalServiceUnavailable) Error() string { + return receiver.err.Error() +} + +func (receiver internalServiceUnavailable) Err() error { + return receiver.err +} + +func (internalServiceUnavailable) ServerError() { + // Nothing here. +} + +func (internalServiceUnavailable) ServiceUnavailable() { + // Nothing here. +} diff --git a/variantaisonegotiates.go b/variantaisonegotiates.go new file mode 100644 index 0000000..56e75a3 --- /dev/null +++ b/variantaisonegotiates.go @@ -0,0 +1,32 @@ +package errhttp + +type VariantAlsoNegotiates interface { + ServerError + VariantAlsoNegotiates() +} + +type internalVariantAlsoNegotiates struct { + err error +} + +func VariantAlsoNegotiatesWrap(err error) error { + return internalVariantAlsoNegotiates{ + err:err, + } +} + +func (receiver internalVariantAlsoNegotiates) Error() string { + return receiver.err.Error() +} + +func (receiver internalVariantAlsoNegotiates) Err() error { + return receiver.err +} + +func (internalVariantAlsoNegotiates) ServerError() { + // Nothing here. +} + +func (internalVariantAlsoNegotiates) VariantAlsoNegotiates() { + // Nothing here. +}