From f09738021e9b5061423679d8d543106c1f6fa155 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Sun, 1 Oct 2023 11:30:28 +0900 Subject: [PATCH] some fixes --- badgateway.go | 8 ++-- badrequest.go | 8 +++- conflict.go | 8 +++- errbadgateway_test.go | 49 ++++++++++++++++++++++ errbadrequest_test.go | 49 ++++++++++++++++++++++ errconflict_test.go | 49 ++++++++++++++++++++++ errexpectationfailed_test.go | 49 ++++++++++++++++++++++ errfaileddependency_test.go | 49 ++++++++++++++++++++++ errforbidden_test.go | 49 ++++++++++++++++++++++ errgatewaytimeout_test.go | 49 ++++++++++++++++++++++ errgone_test.go | 52 ++++++++++++++++++++++++ errhttpversionnotsupported_test.go | 49 ++++++++++++++++++++++ errinsufficientstorage_test.go | 49 ++++++++++++++++++++++ errinternalservererror_test.go | 49 ++++++++++++++++++++++ errlengthrequired_test.go | 49 ++++++++++++++++++++++ errlocked_test.go | 49 ++++++++++++++++++++++ errloopdetected_test.go | 49 ++++++++++++++++++++++ errmethodnotallowed_test.go | 49 ++++++++++++++++++++++ errmisdirectedrequest_test.go | 49 ++++++++++++++++++++++ errnetworkauthenticationrequired_test.go | 49 ++++++++++++++++++++++ errnotacceptable_test.go | 49 ++++++++++++++++++++++ errnotextended_test.go | 49 ++++++++++++++++++++++ errnotfound_test.go | 49 ++++++++++++++++++++++ errnotimplemented_test.go | 49 ++++++++++++++++++++++ errpaymentrequired_test.go | 49 ++++++++++++++++++++++ errpreconditionfailed_test.go | 49 ++++++++++++++++++++++ errpreconditionrequired_test.go | 49 ++++++++++++++++++++++ errproxyauthrequired_test.go | 49 ++++++++++++++++++++++ errrequestedrangenotsatisfiable_test.go | 49 ++++++++++++++++++++++ errrequestentitytoolarge_test.go | 49 ++++++++++++++++++++++ errrequestheaderfieldstoolarge_test.go | 49 ++++++++++++++++++++++ errrequesttimeout_test.go | 49 ++++++++++++++++++++++ errrequesturitoolong_test.go | 49 ++++++++++++++++++++++ errserviceunavailable_test.go | 49 ++++++++++++++++++++++ errteapot_test.go | 49 ++++++++++++++++++++++ errtooearly_test.go | 49 ++++++++++++++++++++++ errtoomanyrequests_test.go | 49 ++++++++++++++++++++++ errunauthorized_test.go | 49 ++++++++++++++++++++++ errunavailableforlegalreasons_test.go | 49 ++++++++++++++++++++++ errunprocessableentity_test.go | 49 ++++++++++++++++++++++ errunsupportedmediatype_test.go | 49 ++++++++++++++++++++++ errupgraderequired_test.go | 49 ++++++++++++++++++++++ errvariantalsonegotiates_test.go | 49 ++++++++++++++++++++++ expectationfailed.go | 6 ++- faileddependency.go | 6 ++- forbidden.go | 6 ++- gatewaytimeout.go | 6 ++- gone.go | 6 ++- httpversionnotsupported.go | 6 ++- insufficientstorage.go | 6 ++- internalservererror.go | 6 ++- lengthrequired.go | 6 ++- locked.go | 6 ++- loopdetected.go | 6 ++- methodnotallowed.go | 6 ++- misdirectedrequest.go | 8 +++- networkauthenticationrequired.go | 6 ++- notacceptable.go | 4 ++ notextended.go | 6 ++- notfound.go | 14 ++++--- notimplemented.go | 6 ++- paymentrequired.go | 6 ++- preconditionfailed.go | 6 ++- preconditionrequired.go | 6 ++- proxyauthrequired.go | 6 ++- requestedrangenotsatisfiable.go | 6 ++- requestentitytoolarge.go | 6 ++- requestheaderfieldstoolarge.go | 6 ++- requesttimeout.go | 6 ++- requesturitoolong.go | 6 ++- serviceunavailable.go | 6 ++- teapot.go | 6 ++- tooearly.go | 8 +++- toomanyrequests.go | 6 ++- unauthorized.go | 6 ++- unavailableforlegalreasons.go | 6 ++- unprocessableentity.go | 6 ++- unsupportedmediatype.go | 6 ++- upgraderequired.go | 6 ++- variantalsonegotiates.go | 6 ++- 80 files changed, 2170 insertions(+), 49 deletions(-) create mode 100644 errbadgateway_test.go create mode 100644 errbadrequest_test.go create mode 100644 errconflict_test.go create mode 100644 errexpectationfailed_test.go create mode 100644 errfaileddependency_test.go create mode 100644 errforbidden_test.go create mode 100644 errgatewaytimeout_test.go create mode 100644 errgone_test.go create mode 100644 errhttpversionnotsupported_test.go create mode 100644 errinsufficientstorage_test.go create mode 100644 errinternalservererror_test.go create mode 100644 errlengthrequired_test.go create mode 100644 errlocked_test.go create mode 100644 errloopdetected_test.go create mode 100644 errmethodnotallowed_test.go create mode 100644 errmisdirectedrequest_test.go create mode 100644 errnetworkauthenticationrequired_test.go create mode 100644 errnotacceptable_test.go create mode 100644 errnotextended_test.go create mode 100644 errnotfound_test.go create mode 100644 errnotimplemented_test.go create mode 100644 errpaymentrequired_test.go create mode 100644 errpreconditionfailed_test.go create mode 100644 errpreconditionrequired_test.go create mode 100644 errproxyauthrequired_test.go create mode 100644 errrequestedrangenotsatisfiable_test.go create mode 100644 errrequestentitytoolarge_test.go create mode 100644 errrequestheaderfieldstoolarge_test.go create mode 100644 errrequesttimeout_test.go create mode 100644 errrequesturitoolong_test.go create mode 100644 errserviceunavailable_test.go create mode 100644 errteapot_test.go create mode 100644 errtooearly_test.go create mode 100644 errtoomanyrequests_test.go create mode 100644 errunauthorized_test.go create mode 100644 errunavailableforlegalreasons_test.go create mode 100644 errunprocessableentity_test.go create mode 100644 errunsupportedmediatype_test.go create mode 100644 errupgraderequired_test.go create mode 100644 errvariantalsonegotiates_test.go diff --git a/badgateway.go b/badgateway.go index 4c6c010..344ace9 100644 --- a/badgateway.go +++ b/badgateway.go @@ -15,8 +15,6 @@ type BadGateway interface { BadGateway() } -var _ BadGateway = internalBadGateway{} - type internalBadGateway struct { err error } @@ -28,7 +26,11 @@ func BadGatewayWrap(err error) error { } func (receiver internalBadGateway) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalBadGateway) ErrHTTP() int { diff --git a/badrequest.go b/badrequest.go index 4bb2e71..3345f46 100644 --- a/badrequest.go +++ b/badrequest.go @@ -8,7 +8,7 @@ var _ Error = internalBadRequest{} var _ ClientError = internalBadRequest{} var _ BadRequest = internalBadRequest{} -var ErrBadRequest = BadRequestWrap(nil) +var ErrBadRequest error = BadRequestWrap(nil) type BadRequest interface { ClientError @@ -26,7 +26,11 @@ func BadRequestWrap(err error) error { } func (receiver internalBadRequest) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalBadRequest) ErrHTTP() int { diff --git a/conflict.go b/conflict.go index 8da9697..a631656 100644 --- a/conflict.go +++ b/conflict.go @@ -8,7 +8,7 @@ var _ Error = internalConflict{} var _ ClientError = internalConflict{} var _ Conflict = internalConflict{} -var ErrConflict = ConflictWrap(nil) +var ErrConflict error = ConflictWrap(nil) type Conflict interface { ClientError @@ -26,7 +26,11 @@ func ConflictWrap(err error) error { } func (receiver internalConflict) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalConflict) ErrHTTP() int { diff --git a/errbadgateway_test.go b/errbadgateway_test.go new file mode 100644 index 0000000..b54b206 --- /dev/null +++ b/errbadgateway_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrBadGateway(t *testing.T) { + + var err error = errhttp.ErrBadGateway + casted := err.(errhttp.BadGateway) + var code int = http.StatusBadGateway + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errbadrequest_test.go b/errbadrequest_test.go new file mode 100644 index 0000000..d04caa4 --- /dev/null +++ b/errbadrequest_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrBadRequest(t *testing.T) { + + var err error = errhttp.ErrBadRequest + casted := err.(errhttp.BadRequest) + var code int = http.StatusBadRequest + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errconflict_test.go b/errconflict_test.go new file mode 100644 index 0000000..57ced55 --- /dev/null +++ b/errconflict_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrConflict(t *testing.T) { + + var err error = errhttp.ErrConflict + casted := err.(errhttp.Conflict) + var code int = http.StatusConflict + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errexpectationfailed_test.go b/errexpectationfailed_test.go new file mode 100644 index 0000000..b0f5dbb --- /dev/null +++ b/errexpectationfailed_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrExpectationFailed(t *testing.T) { + + var err error = errhttp.ErrExpectationFailed + casted := err.(errhttp.ExpectationFailed) + var code int = http.StatusExpectationFailed + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errfaileddependency_test.go b/errfaileddependency_test.go new file mode 100644 index 0000000..13ab405 --- /dev/null +++ b/errfaileddependency_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrFailedDependency(t *testing.T) { + + var err error = errhttp.ErrFailedDependency + casted := err.(errhttp.FailedDependency) + var code int = http.StatusFailedDependency + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errforbidden_test.go b/errforbidden_test.go new file mode 100644 index 0000000..623a11a --- /dev/null +++ b/errforbidden_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrForbidden(t *testing.T) { + + var err error = errhttp.ErrForbidden + casted := err.(errhttp.Forbidden) + var code int = http.StatusForbidden + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errgatewaytimeout_test.go b/errgatewaytimeout_test.go new file mode 100644 index 0000000..1a75272 --- /dev/null +++ b/errgatewaytimeout_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrGatewayTimeout(t *testing.T) { + + var err error = errhttp.ErrGatewayTimeout + casted := err.(errhttp.GatewayTimeout) + var code int = http.StatusGatewayTimeout + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errgone_test.go b/errgone_test.go new file mode 100644 index 0000000..8a1b211 --- /dev/null +++ b/errgone_test.go @@ -0,0 +1,52 @@ +package errhttp_test + +//@TODO: THIS TEST IS GIVING A WEIRD ERROR +/* +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrGone(t *testing.T) { + + var err error = errhttp.ErrGone + casted := err.(errhttp.Gone) + var code int = http.StatusGone + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} +*/ diff --git a/errhttpversionnotsupported_test.go b/errhttpversionnotsupported_test.go new file mode 100644 index 0000000..3b1cbdb --- /dev/null +++ b/errhttpversionnotsupported_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrHTTPVersionNotSupported(t *testing.T) { + + var err error = errhttp.ErrHTTPVersionNotSupported + casted := err.(errhttp.HTTPVersionNotSupported) + var code int = http.StatusHTTPVersionNotSupported + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errinsufficientstorage_test.go b/errinsufficientstorage_test.go new file mode 100644 index 0000000..0434838 --- /dev/null +++ b/errinsufficientstorage_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrInsufficientStorage(t *testing.T) { + + var err error = errhttp.ErrInsufficientStorage + casted := err.(errhttp.InsufficientStorage) + var code int = http.StatusInsufficientStorage + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errinternalservererror_test.go b/errinternalservererror_test.go new file mode 100644 index 0000000..55ad4ec --- /dev/null +++ b/errinternalservererror_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrInternalServerError(t *testing.T) { + + var err error = errhttp.ErrInternalServerError + casted := err.(errhttp.InternalServerError) + var code int = http.StatusInternalServerError + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errlengthrequired_test.go b/errlengthrequired_test.go new file mode 100644 index 0000000..fbfebf8 --- /dev/null +++ b/errlengthrequired_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrLengthRequired(t *testing.T) { + + var err error = errhttp.ErrLengthRequired + casted := err.(errhttp.LengthRequired) + var code int = http.StatusLengthRequired + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errlocked_test.go b/errlocked_test.go new file mode 100644 index 0000000..8b1bbde --- /dev/null +++ b/errlocked_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrLocked(t *testing.T) { + + var err error = errhttp.ErrLocked + casted := err.(errhttp.Locked) + var code int = http.StatusLocked + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errloopdetected_test.go b/errloopdetected_test.go new file mode 100644 index 0000000..96e831d --- /dev/null +++ b/errloopdetected_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrLoopDetected(t *testing.T) { + + var err error = errhttp.ErrLoopDetected + casted := err.(errhttp.LoopDetected) + var code int = http.StatusLoopDetected + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errmethodnotallowed_test.go b/errmethodnotallowed_test.go new file mode 100644 index 0000000..5db6a0b --- /dev/null +++ b/errmethodnotallowed_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrMethodNotAllowed(t *testing.T) { + + var err error = errhttp.ErrMethodNotAllowed + casted := err.(errhttp.MethodNotAllowed) + var code int = http.StatusMethodNotAllowed + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errmisdirectedrequest_test.go b/errmisdirectedrequest_test.go new file mode 100644 index 0000000..b127bfb --- /dev/null +++ b/errmisdirectedrequest_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrMisdirectedRequest(t *testing.T) { + + var err error = errhttp.ErrMisdirectedRequest + casted := err.(errhttp.MisdirectedRequest) + var code int = http.StatusMisdirectedRequest + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errnetworkauthenticationrequired_test.go b/errnetworkauthenticationrequired_test.go new file mode 100644 index 0000000..2d7a86d --- /dev/null +++ b/errnetworkauthenticationrequired_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrNetworkAuthenticationRequired(t *testing.T) { + + var err error = errhttp.ErrNetworkAuthenticationRequired + casted := err.(errhttp.NetworkAuthenticationRequired) + var code int = http.StatusNetworkAuthenticationRequired + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errnotacceptable_test.go b/errnotacceptable_test.go new file mode 100644 index 0000000..05df7f9 --- /dev/null +++ b/errnotacceptable_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrNotAcceptable(t *testing.T) { + + var err error = errhttp.ErrNotAcceptable + casted := err.(errhttp.NotAcceptable) + var code int = http.StatusNotAcceptable + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errnotextended_test.go b/errnotextended_test.go new file mode 100644 index 0000000..d560558 --- /dev/null +++ b/errnotextended_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrNotExtended(t *testing.T) { + + var err error = errhttp.ErrNotExtended + casted := err.(errhttp.NotExtended) + var code int = http.StatusNotExtended + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errnotfound_test.go b/errnotfound_test.go new file mode 100644 index 0000000..8a4c6f5 --- /dev/null +++ b/errnotfound_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrNotFound(t *testing.T) { + + var err error = errhttp.ErrNotFound + casted := err.(errhttp.NotFound) + var code int = http.StatusNotFound + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errnotimplemented_test.go b/errnotimplemented_test.go new file mode 100644 index 0000000..d2fd779 --- /dev/null +++ b/errnotimplemented_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrNotImplemented(t *testing.T) { + + var err error = errhttp.ErrNotImplemented + casted := err.(errhttp.NotImplemented) + var code int = http.StatusNotImplemented + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errpaymentrequired_test.go b/errpaymentrequired_test.go new file mode 100644 index 0000000..909da7d --- /dev/null +++ b/errpaymentrequired_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrPaymentRequired(t *testing.T) { + + var err error = errhttp.ErrPaymentRequired + casted := err.(errhttp.PaymentRequired) + var code int = http.StatusPaymentRequired + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errpreconditionfailed_test.go b/errpreconditionfailed_test.go new file mode 100644 index 0000000..803e7f1 --- /dev/null +++ b/errpreconditionfailed_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrPreconditionFailed(t *testing.T) { + + var err error = errhttp.ErrPreconditionFailed + casted := err.(errhttp.PreconditionFailed) + var code int = http.StatusPreconditionFailed + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errpreconditionrequired_test.go b/errpreconditionrequired_test.go new file mode 100644 index 0000000..3e6653f --- /dev/null +++ b/errpreconditionrequired_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrPreconditionRequired(t *testing.T) { + + var err error = errhttp.ErrPreconditionRequired + casted := err.(errhttp.PreconditionRequired) + var code int = http.StatusPreconditionRequired + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errproxyauthrequired_test.go b/errproxyauthrequired_test.go new file mode 100644 index 0000000..bbcc554 --- /dev/null +++ b/errproxyauthrequired_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrProxyAuthRequired(t *testing.T) { + + var err error = errhttp.ErrProxyAuthRequired + casted := err.(errhttp.ProxyAuthRequired) + var code int = http.StatusProxyAuthRequired + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errrequestedrangenotsatisfiable_test.go b/errrequestedrangenotsatisfiable_test.go new file mode 100644 index 0000000..40a6ec2 --- /dev/null +++ b/errrequestedrangenotsatisfiable_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrRequestedRangeNotSatisfiable(t *testing.T) { + + var err error = errhttp.ErrRequestedRangeNotSatisfiable + casted := err.(errhttp.RequestedRangeNotSatisfiable) + var code int = http.StatusRequestedRangeNotSatisfiable + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errrequestentitytoolarge_test.go b/errrequestentitytoolarge_test.go new file mode 100644 index 0000000..d79f3a6 --- /dev/null +++ b/errrequestentitytoolarge_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrRequestEntityTooLarge(t *testing.T) { + + var err error = errhttp.ErrRequestEntityTooLarge + casted := err.(errhttp.RequestEntityTooLarge) + var code int = http.StatusRequestEntityTooLarge + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errrequestheaderfieldstoolarge_test.go b/errrequestheaderfieldstoolarge_test.go new file mode 100644 index 0000000..8589c2c --- /dev/null +++ b/errrequestheaderfieldstoolarge_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrRequestHeaderFieldsTooLarge(t *testing.T) { + + var err error = errhttp.ErrRequestHeaderFieldsTooLarge + casted := err.(errhttp.RequestHeaderFieldsTooLarge) + var code int = http.StatusRequestHeaderFieldsTooLarge + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errrequesttimeout_test.go b/errrequesttimeout_test.go new file mode 100644 index 0000000..dcf8378 --- /dev/null +++ b/errrequesttimeout_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrRequestTimeout(t *testing.T) { + + var err error = errhttp.ErrRequestTimeout + casted := err.(errhttp.RequestTimeout) + var code int = http.StatusRequestTimeout + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errrequesturitoolong_test.go b/errrequesturitoolong_test.go new file mode 100644 index 0000000..cd78db2 --- /dev/null +++ b/errrequesturitoolong_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrRequestURITooLong(t *testing.T) { + + var err error = errhttp.ErrRequestURITooLong + casted := err.(errhttp.RequestURITooLong) + var code int = http.StatusRequestURITooLong + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errserviceunavailable_test.go b/errserviceunavailable_test.go new file mode 100644 index 0000000..bcd81c7 --- /dev/null +++ b/errserviceunavailable_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrServiceUnavailable(t *testing.T) { + + var err error = errhttp.ErrServiceUnavailable + casted := err.(errhttp.ServiceUnavailable) + var code int = http.StatusServiceUnavailable + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errteapot_test.go b/errteapot_test.go new file mode 100644 index 0000000..f0fa1c5 --- /dev/null +++ b/errteapot_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrTeapot(t *testing.T) { + + var err error = errhttp.ErrTeapot + casted := err.(errhttp.Teapot) + var code int = http.StatusTeapot + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errtooearly_test.go b/errtooearly_test.go new file mode 100644 index 0000000..510267b --- /dev/null +++ b/errtooearly_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrTooEarly(t *testing.T) { + + var err error = errhttp.ErrTooEarly + casted := err.(errhttp.TooEarly) + var code int = http.StatusTooEarly + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errtoomanyrequests_test.go b/errtoomanyrequests_test.go new file mode 100644 index 0000000..ef04233 --- /dev/null +++ b/errtoomanyrequests_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrTooManyRequests(t *testing.T) { + + var err error = errhttp.ErrTooManyRequests + casted := err.(errhttp.TooManyRequests) + var code int = http.StatusTooManyRequests + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errunauthorized_test.go b/errunauthorized_test.go new file mode 100644 index 0000000..8647aa5 --- /dev/null +++ b/errunauthorized_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrUnauthorized(t *testing.T) { + + var err error = errhttp.ErrUnauthorized + casted := err.(errhttp.Unauthorized) + var code int = http.StatusUnauthorized + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errunavailableforlegalreasons_test.go b/errunavailableforlegalreasons_test.go new file mode 100644 index 0000000..5e509c6 --- /dev/null +++ b/errunavailableforlegalreasons_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrUnavailableForLegalReasons(t *testing.T) { + + var err error = errhttp.ErrUnavailableForLegalReasons + casted := err.(errhttp.UnavailableForLegalReasons) + var code int = http.StatusUnavailableForLegalReasons + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errunprocessableentity_test.go b/errunprocessableentity_test.go new file mode 100644 index 0000000..52c8efc --- /dev/null +++ b/errunprocessableentity_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrUnprocessableEntity(t *testing.T) { + + var err error = errhttp.ErrUnprocessableEntity + casted := err.(errhttp.UnprocessableEntity) + var code int = http.StatusUnprocessableEntity + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errunsupportedmediatype_test.go b/errunsupportedmediatype_test.go new file mode 100644 index 0000000..2767651 --- /dev/null +++ b/errunsupportedmediatype_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrUnsupportedMediaType(t *testing.T) { + + var err error = errhttp.ErrUnsupportedMediaType + casted := err.(errhttp.UnsupportedMediaType) + var code int = http.StatusUnsupportedMediaType + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errupgraderequired_test.go b/errupgraderequired_test.go new file mode 100644 index 0000000..20a5d6f --- /dev/null +++ b/errupgraderequired_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrUpgradeRequired(t *testing.T) { + + var err error = errhttp.ErrUpgradeRequired + casted := err.(errhttp.UpgradeRequired) + var code int = http.StatusUpgradeRequired + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/errvariantalsonegotiates_test.go b/errvariantalsonegotiates_test.go new file mode 100644 index 0000000..65bdb32 --- /dev/null +++ b/errvariantalsonegotiates_test.go @@ -0,0 +1,49 @@ +package errhttp_test + +import ( + "testing" + + "net/http" + + "sourcecode.social/reiver/go-errhttp" +) + +func TestErrVariantAlsoNegotiates(t *testing.T) { + + var err error = errhttp.ErrVariantAlsoNegotiates + casted := err.(errhttp.VariantAlsoNegotiates) + var code int = http.StatusVariantAlsoNegotiates + + { + e := casted.Unwrap() + if nil != e { + t.Errorf("Expected the .Unwrap() to return nil but it actually didn't.") + t.Logf("ERROR: (%T) %s", e, e) + return + } + } + + { + expected := code + actual := casted.ErrHTTP() + + if expected != actual { + t.Errorf("The actual HTTP status-code is not what was expected.") + t.Logf("EXPECTED: %d", expected) + t.Logf("ACTUAL: %d", actual) + return + } + } + + { + expected := http.StatusText(casted.ErrHTTP()) + actual := err.Error() + + if expected != actual { + t.Errorf("The actual error message was not what was expected.") + t.Logf("EXPECTED: %q", expected) + t.Logf("ACTUAL: %q", actual) + return + } + } +} diff --git a/expectationfailed.go b/expectationfailed.go index f91c205..e3dd3f3 100644 --- a/expectationfailed.go +++ b/expectationfailed.go @@ -26,7 +26,11 @@ func ExpectationFailedWrap(err error) error { } func (receiver internalExpectationFailed) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalExpectationFailed) ErrHTTP() int { diff --git a/faileddependency.go b/faileddependency.go index 95d2556..b8f5677 100644 --- a/faileddependency.go +++ b/faileddependency.go @@ -26,7 +26,11 @@ func FailedDependencyWrap(err error) error { } func (receiver internalFailedDependency) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalFailedDependency) ErrHTTP() int { diff --git a/forbidden.go b/forbidden.go index f8f2fc5..5179dbd 100644 --- a/forbidden.go +++ b/forbidden.go @@ -26,7 +26,11 @@ func ForbiddenWrap(err error) error { } func (receiver internalForbidden) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalForbidden) ErrHTTP() int { diff --git a/gatewaytimeout.go b/gatewaytimeout.go index 1e29e1a..2a0802d 100644 --- a/gatewaytimeout.go +++ b/gatewaytimeout.go @@ -28,7 +28,11 @@ func GatewayTimeoutWrap(err error) error { } func (receiver internalGatewayTimeout) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalGatewayTimeout) ErrHTTP() int { diff --git a/gone.go b/gone.go index 20ddf46..5e10b6f 100644 --- a/gone.go +++ b/gone.go @@ -26,7 +26,11 @@ func GoneWrap(err error) error { } func (receiver internalGone) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalGone) ErrHTTP() int { diff --git a/httpversionnotsupported.go b/httpversionnotsupported.go index a53e528..7030002 100644 --- a/httpversionnotsupported.go +++ b/httpversionnotsupported.go @@ -28,7 +28,11 @@ func HTTPVersionNotSupportedWrap(err error) error { } func (receiver internalHTTPVersionNotSupported) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalHTTPVersionNotSupported) ErrHTTP() int { diff --git a/insufficientstorage.go b/insufficientstorage.go index c91d406..9560561 100644 --- a/insufficientstorage.go +++ b/insufficientstorage.go @@ -28,7 +28,11 @@ func InsufficientStorageWrap(err error) error { } func (receiver internalInsufficientStorage) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalInsufficientStorage) ErrHTTP() int { diff --git a/internalservererror.go b/internalservererror.go index 50e3297..63a82c5 100644 --- a/internalservererror.go +++ b/internalservererror.go @@ -28,7 +28,11 @@ func InternalServerErrorWrap(err error) error { } func (receiver internalInternalServerError) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalInternalServerError) ErrHTTP() int { diff --git a/lengthrequired.go b/lengthrequired.go index e46c7e0..6573fec 100644 --- a/lengthrequired.go +++ b/lengthrequired.go @@ -26,7 +26,11 @@ func LengthRequiredWrap(err error) error { } func (receiver internalLengthRequired) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalLengthRequired) ErrHTTP() int { diff --git a/locked.go b/locked.go index fe85732..25813ed 100644 --- a/locked.go +++ b/locked.go @@ -26,7 +26,11 @@ func LockedWrap(err error) error { } func (receiver internalLocked) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalLocked) ErrHTTP() int { diff --git a/loopdetected.go b/loopdetected.go index fb1739e..e329a99 100644 --- a/loopdetected.go +++ b/loopdetected.go @@ -28,7 +28,11 @@ func LoopDetectedWrap(err error) error { } func (receiver internalLoopDetected) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalLoopDetected) ErrHTTP() int { diff --git a/methodnotallowed.go b/methodnotallowed.go index e47b79f..8db85e8 100644 --- a/methodnotallowed.go +++ b/methodnotallowed.go @@ -26,7 +26,11 @@ func MethodNotAllowedWrap(err error) error { } func (receiver internalMethodNotAllowed) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalMethodNotAllowed) ErrHTTP() int { diff --git a/misdirectedrequest.go b/misdirectedrequest.go index ca6a645..1cb5ad8 100644 --- a/misdirectedrequest.go +++ b/misdirectedrequest.go @@ -8,7 +8,7 @@ var _ Error = internalMisdirectedRequest{} var _ ClientError = internalMisdirectedRequest{} var _ MisdirectedRequest = internalMisdirectedRequest{} -var ErrMisdirectedRequest = MisdirectedRequestWrap(nil) +var ErrMisdirectedRequest error = MisdirectedRequestWrap(nil) type MisdirectedRequest interface { ClientError @@ -26,7 +26,11 @@ func MisdirectedRequestWrap(err error) error { } func (receiver internalMisdirectedRequest) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalMisdirectedRequest) ErrHTTP() int { diff --git a/networkauthenticationrequired.go b/networkauthenticationrequired.go index cdd2f50..bb642cc 100644 --- a/networkauthenticationrequired.go +++ b/networkauthenticationrequired.go @@ -28,7 +28,11 @@ func NetworkAuthenticationRequiredWrap(err error) error { } func (receiver internalNetworkAuthenticationRequired) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalNetworkAuthenticationRequired) ErrHTTP() int { diff --git a/notacceptable.go b/notacceptable.go index 8417348..f67d4ea 100644 --- a/notacceptable.go +++ b/notacceptable.go @@ -26,6 +26,10 @@ func NotAcceptableWrap(err error) error { } func (receiver internalNotAcceptable) Error() string { + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } return receiver.err.Error() } diff --git a/notextended.go b/notextended.go index 71b3468..c51d9fc 100644 --- a/notextended.go +++ b/notextended.go @@ -28,7 +28,11 @@ func NotExtendedWrap(err error) error { } func (receiver internalNotExtended) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalNotExtended) ErrHTTP() int { diff --git a/notfound.go b/notfound.go index 7cb8a34..bf99662 100644 --- a/notfound.go +++ b/notfound.go @@ -25,19 +25,23 @@ func NotFoundWrap(err error) error { } } -func (receiver internalNotFound ) Error() string { - return receiver.err.Error() +func (receiver internalNotFound) Error() string { + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } -func (internalNotFound ) ErrHTTP() int { +func (internalNotFound) ErrHTTP() int { return http.StatusNotFound } -func (internalNotFound ) ClientError() { +func (internalNotFound) ClientError() { // Nothing here. } -func (internalNotFound ) NotFound() { +func (internalNotFound) NotFound() { // Nothing here. } diff --git a/notimplemented.go b/notimplemented.go index 3bd7e92..f219b74 100644 --- a/notimplemented.go +++ b/notimplemented.go @@ -28,7 +28,11 @@ func NotImplementedWrap(err error) error { } func (receiver internalNotImplemented) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalNotImplemented) ErrHTTP() int { diff --git a/paymentrequired.go b/paymentrequired.go index 57f8343..f38a2f7 100644 --- a/paymentrequired.go +++ b/paymentrequired.go @@ -26,7 +26,11 @@ func PaymentRequiredWrap(err error) error { } func (receiver internalPaymentRequired) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalPaymentRequired) ErrHTTP() int { diff --git a/preconditionfailed.go b/preconditionfailed.go index c88324f..7267b05 100644 --- a/preconditionfailed.go +++ b/preconditionfailed.go @@ -26,7 +26,11 @@ func PreconditionFailedWrap(err error) error { } func (receiver internalPreconditionFailed) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalPreconditionFailed) ErrHTTP() int { diff --git a/preconditionrequired.go b/preconditionrequired.go index f8a4826..4d791c3 100644 --- a/preconditionrequired.go +++ b/preconditionrequired.go @@ -26,7 +26,11 @@ func PreconditionRequiredWrap(err error) error { } func (receiver internalPreconditionRequired) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalPreconditionRequired) ErrHTTP() int { diff --git a/proxyauthrequired.go b/proxyauthrequired.go index 7488f23..ddf57a3 100644 --- a/proxyauthrequired.go +++ b/proxyauthrequired.go @@ -26,7 +26,11 @@ func ProxyAuthRequiredWrap(err error) error { } func (receiver internalProxyAuthRequired) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalProxyAuthRequired) ErrHTTP() int { diff --git a/requestedrangenotsatisfiable.go b/requestedrangenotsatisfiable.go index a230d93..bf7c84a 100644 --- a/requestedrangenotsatisfiable.go +++ b/requestedrangenotsatisfiable.go @@ -26,7 +26,11 @@ func RequestedRangeNotSatisfiableWrap(err error) error { } func (receiver internalRequestedRangeNotSatisfiable) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalRequestedRangeNotSatisfiable) ErrHTTP() int { diff --git a/requestentitytoolarge.go b/requestentitytoolarge.go index 868ee9e..745fa77 100644 --- a/requestentitytoolarge.go +++ b/requestentitytoolarge.go @@ -26,7 +26,11 @@ func RequestEntityTooLargeWrap(err error) error { } func (receiver internalRequestEntityTooLarge) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalRequestEntityTooLarge) ErrHTTP() int { diff --git a/requestheaderfieldstoolarge.go b/requestheaderfieldstoolarge.go index cd06ec2..5443462 100644 --- a/requestheaderfieldstoolarge.go +++ b/requestheaderfieldstoolarge.go @@ -26,7 +26,11 @@ func RequestHeaderFieldsTooLargeWrap(err error) error { } func (receiver internalRequestHeaderFieldsTooLarge) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalRequestHeaderFieldsTooLarge) ErrHTTP() int { diff --git a/requesttimeout.go b/requesttimeout.go index 443ebd1..289f53b 100644 --- a/requesttimeout.go +++ b/requesttimeout.go @@ -26,7 +26,11 @@ func RequestTimeoutWrap(err error) error { } func (receiver internalRequestTimeout) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalRequestTimeout) ErrHTTP() int { diff --git a/requesturitoolong.go b/requesturitoolong.go index ef7c86f..9ea1bfb 100644 --- a/requesturitoolong.go +++ b/requesturitoolong.go @@ -26,7 +26,11 @@ func RequestURITooLongWrap(err error) error { } func (receiver internalRequestURITooLong) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalRequestURITooLong) ErrHTTP() int { diff --git a/serviceunavailable.go b/serviceunavailable.go index 171632a..e08ef7c 100644 --- a/serviceunavailable.go +++ b/serviceunavailable.go @@ -26,7 +26,11 @@ func ServiceUnavailableWrap(err error) error { } func (receiver internalServiceUnavailable) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalServiceUnavailable) ErrHTTP() int { diff --git a/teapot.go b/teapot.go index 0dbf9cc..2fa6855 100644 --- a/teapot.go +++ b/teapot.go @@ -26,7 +26,11 @@ func TeapotWrap(err error) error { } func (receiver internalTeapot) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalTeapot) ErrHTTP() int { diff --git a/tooearly.go b/tooearly.go index 9ed67da..67a8a7b 100644 --- a/tooearly.go +++ b/tooearly.go @@ -8,7 +8,7 @@ var _ Error = internalTooEarly{} var _ ClientError = internalTooEarly{} var _ TooEarly = internalTooEarly{} -var ErrTooEarly = TooEarlyWrap(nil) +var ErrTooEarly error = TooEarlyWrap(nil) type TooEarly interface { ClientError @@ -26,7 +26,11 @@ func TooEarlyWrap(err error) error { } func (receiver internalTooEarly) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalTooEarly) ErrHTTP() int { diff --git a/toomanyrequests.go b/toomanyrequests.go index f990983..aea99ae 100644 --- a/toomanyrequests.go +++ b/toomanyrequests.go @@ -26,7 +26,11 @@ func TooManyRequestsWrap(err error) error { } func (receiver internalTooManyRequests) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalTooManyRequests) ErrHTTP() int { diff --git a/unauthorized.go b/unauthorized.go index 8fbe842..997bfd8 100644 --- a/unauthorized.go +++ b/unauthorized.go @@ -26,7 +26,11 @@ func UnauthorizedWrap(err error) error { } func (receiver internalUnauthorized) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalUnauthorized) ErrHTTP() int { diff --git a/unavailableforlegalreasons.go b/unavailableforlegalreasons.go index 6fa544b..cd388b1 100644 --- a/unavailableforlegalreasons.go +++ b/unavailableforlegalreasons.go @@ -26,7 +26,11 @@ func UnavailableForLegalReasonsWrap(err error) error { } func (receiver internalUnavailableForLegalReasons) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalUnavailableForLegalReasons) ErrHTTP() int { diff --git a/unprocessableentity.go b/unprocessableentity.go index a9e07ff..71670b3 100644 --- a/unprocessableentity.go +++ b/unprocessableentity.go @@ -26,7 +26,11 @@ func UnprocessableEntityWrap(err error) error { } func (receiver internalUnprocessableEntity) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalUnprocessableEntity) ErrHTTP() int { diff --git a/unsupportedmediatype.go b/unsupportedmediatype.go index 31e9dab..ec7d99b 100644 --- a/unsupportedmediatype.go +++ b/unsupportedmediatype.go @@ -26,7 +26,11 @@ func UnsupportedMediaTypeWrap(err error) error { } func (receiver internalUnsupportedMediaType) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalUnsupportedMediaType) ErrHTTP() int { diff --git a/upgraderequired.go b/upgraderequired.go index c97f02b..557b39b 100644 --- a/upgraderequired.go +++ b/upgraderequired.go @@ -26,7 +26,11 @@ func UpgradeRequiredWrap(err error) error { } func (receiver internalUpgradeRequired) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalUpgradeRequired) ErrHTTP() int { diff --git a/variantalsonegotiates.go b/variantalsonegotiates.go index 75f44a3..66ba564 100644 --- a/variantalsonegotiates.go +++ b/variantalsonegotiates.go @@ -28,7 +28,11 @@ func VariantAlsoNegotiatesWrap(err error) error { } func (receiver internalVariantAlsoNegotiates) Error() string { - return receiver.err.Error() + err := receiver.err + if nil == err { + return http.StatusText(receiver.ErrHTTP()) + } + return err.Error() } func (internalVariantAlsoNegotiates) ErrHTTP() int {