made .ErrHTTP() method return the HTTP status code (as an int). added some missing error. removed some errors that should not have been there.

master
Charles Iliya Krempeaux 2023-08-14 06:56:09 -07:00
parent 2f430f79b6
commit ab4070bfdf
44 changed files with 352 additions and 165 deletions

View File

@ -30,12 +30,12 @@ Here is an example of wrapping an error:
//@TODO //@TODO
case errhttp.InternalServerError: case errhttp.InternalServerError:
//@TODO //@TODO
case errhttp.ClientError: case errhttp.ClientError:
//@TODO //@TODO
case errhttp.ServerError: case errhttp.ServerError:
//@TODO //@TODO
default: default:
//@TODO //@TODO
} }
@ -59,12 +59,39 @@ Here is an example of using one of the package global variable errors:
//@TODO //@TODO
case errhttp.InternalServerError: case errhttp.InternalServerError:
//@TODO //@TODO
case errhttp.ClientError: case errhttp.ClientError:
//@TODO //@TODO
case errhttp.ServerError: case errhttp.ServerError:
//@TODO //@TODO
default:
//@TODO
}
```
Here is another example, where it used the `.ErrHTTP()` method to get the HTTP response status code:
```go
import "sourcecode.social/reiver/go-errhttp"
// ...
return errhttp.ErrBadRequest
// ...
switch casted := err.(type) {
case errhttp.ClientError:
statuscode := casted.ErrHTTP()
http.Error(responsewriter, http.StatusText(statuscode), statuscode)
return
case errhttp.ServerError:
statuscode := casted.ErrHTTP()
http.Error(responsewriter, http.StatusText(statuscode), statuscode)
return
default: default:
//@TODO //@TODO
} }

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalBadGateway{} var _ Error = internalBadGateway{}
var _ ServerError = internalBadGateway{} var _ ServerError = internalBadGateway{}
var _ BadGateway = internalBadGateway{} var _ BadGateway = internalBadGateway{}
@ -27,8 +31,8 @@ func (receiver internalBadGateway) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalBadGateway) ErrHTTP() { func (internalBadGateway) ErrHTTP() int {
// Nothing here. return http.StatusBadGateway
} }
func (internalBadGateway) ServerError() { func (internalBadGateway) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalBadRequest{} var _ Error = internalBadRequest{}
var _ ClientError = internalBadRequest{} var _ ClientError = internalBadRequest{}
var _ BadRequest = internalBadRequest{} var _ BadRequest = internalBadRequest{}
@ -25,8 +29,8 @@ func (receiver internalBadRequest) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalBadRequest) ErrHTTP() { func (internalBadRequest) ErrHTTP() int {
// Nothing here. return http.StatusBadRequest
} }
func (internalBadRequest) ClientError() { func (internalBadRequest) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalConflict{} var _ Error = internalConflict{}
var _ ClientError = internalConflict{} var _ ClientError = internalConflict{}
var _ Conflict = internalConflict{} var _ Conflict = internalConflict{}
@ -25,8 +29,8 @@ func (receiver internalConflict) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalConflict) ErrHTTP() { func (internalConflict) ErrHTTP() int {
// Nothing here. return http.StatusConflict
} }
func (internalConflict) ClientError() { func (internalConflict) ClientError() {

View File

@ -2,6 +2,6 @@ package errhttp
type Error interface { type Error interface {
error error
ErrHTTP() ErrHTTP() int
Unwrap() error Unwrap() error
} }

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalExpectationFailed{} var _ Error = internalExpectationFailed{}
var _ ClientError = internalExpectationFailed{} var _ ClientError = internalExpectationFailed{}
var _ ExpectationFailed = internalExpectationFailed{} var _ ExpectationFailed = internalExpectationFailed{}
@ -25,8 +29,8 @@ func (receiver internalExpectationFailed) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalExpectationFailed) ErrHTTP() { func (internalExpectationFailed) ErrHTTP() int {
// Nothing here. return http.StatusExpectationFailed
} }
func (internalExpectationFailed) ClientError() { func (internalExpectationFailed) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalFailedDependency{} var _ Error = internalFailedDependency{}
var _ ClientError = internalFailedDependency{} var _ ClientError = internalFailedDependency{}
var _ FailedDependency = internalFailedDependency{} var _ FailedDependency = internalFailedDependency{}
@ -25,8 +29,8 @@ func (receiver internalFailedDependency) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalFailedDependency) ErrHTTP() { func (internalFailedDependency) ErrHTTP() int {
// Nothing here. return http.StatusFailedDependency
} }
func (internalFailedDependency) ClientError() { func (internalFailedDependency) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalForbidden{} var _ Error = internalForbidden{}
var _ ClientError = internalForbidden{} var _ ClientError = internalForbidden{}
var _ Forbidden = internalForbidden{} var _ Forbidden = internalForbidden{}
@ -25,8 +29,8 @@ func (receiver internalForbidden) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalForbidden) ErrHTTP() { func (internalForbidden) ErrHTTP() int {
// Nothing here. return http.StatusForbidden
} }
func (internalForbidden) ClientError() { func (internalForbidden) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalGatewayTimeout{} var _ Error = internalGatewayTimeout{}
var _ ServerError = internalGatewayTimeout{} var _ ServerError = internalGatewayTimeout{}
var _ GatewayTimeout = internalGatewayTimeout{} var _ GatewayTimeout = internalGatewayTimeout{}
@ -27,8 +31,8 @@ func (receiver internalGatewayTimeout) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalGatewayTimeout) ErrHTTP() { func (internalGatewayTimeout) ErrHTTP() int {
// Nothing here. return http.StatusGatewayTimeout
} }
func (internalGatewayTimeout) ServerError() { func (internalGatewayTimeout) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalGone{} var _ Error = internalGone{}
var _ ClientError = internalGone{} var _ ClientError = internalGone{}
var _ Gone = internalGone{} var _ Gone = internalGone{}
@ -25,8 +29,8 @@ func (receiver internalGone) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalGone) ErrHTTP() { func (internalGone) ErrHTTP() int {
// Nothing here. return http.StatusGone
} }
func (internalGone) ClientError() { func (internalGone) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalHTTPVersionNotSupported{} var _ Error = internalHTTPVersionNotSupported{}
var _ ServerError = internalHTTPVersionNotSupported{} var _ ServerError = internalHTTPVersionNotSupported{}
var _ HTTPVersionNotSupported = internalHTTPVersionNotSupported{} var _ HTTPVersionNotSupported = internalHTTPVersionNotSupported{}
@ -27,8 +31,8 @@ func (receiver internalHTTPVersionNotSupported) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalHTTPVersionNotSupported) ErrHTTP() { func (internalHTTPVersionNotSupported) ErrHTTP() int {
// Nothing here. return http.StatusHTTPVersionNotSupported
} }
func (internalHTTPVersionNotSupported) ServerError() { func (internalHTTPVersionNotSupported) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalInsufficientStorage{} var _ Error = internalInsufficientStorage{}
var _ ServerError = internalInsufficientStorage{} var _ ServerError = internalInsufficientStorage{}
var _ InsufficientStorage = internalInsufficientStorage{} var _ InsufficientStorage = internalInsufficientStorage{}
@ -27,8 +31,8 @@ func (receiver internalInsufficientStorage) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalInsufficientStorage) ErrHTTP() { func (internalInsufficientStorage) ErrHTTP() int {
// Nothing here. return http.StatusInsufficientStorage
} }
func (internalInsufficientStorage) ServerError() { func (internalInsufficientStorage) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalInternalServerError{} var _ Error = internalInternalServerError{}
var _ ServerError = internalInternalServerError{} var _ ServerError = internalInternalServerError{}
var _ InternalServerError = internalInternalServerError{} var _ InternalServerError = internalInternalServerError{}
@ -27,8 +31,8 @@ func (receiver internalInternalServerError) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalInternalServerError) ErrHTTP() { func (internalInternalServerError) ErrHTTP() int {
// Nothing here. return http.StatusInternalServerError
} }
func (internalInternalServerError) ServerError() { func (internalInternalServerError) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalLengthRequired{} var _ Error = internalLengthRequired{}
var _ ClientError = internalLengthRequired{} var _ ClientError = internalLengthRequired{}
var _ LengthRequired = internalLengthRequired{} var _ LengthRequired = internalLengthRequired{}
@ -25,8 +29,8 @@ func (receiver internalLengthRequired) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalLengthRequired) ErrHTTP() { func (internalLengthRequired) ErrHTTP() int {
// Nothing here. return http.StatusLengthRequired
} }
func (internalLengthRequired) ClientError() { func (internalLengthRequired) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalLocked{} var _ Error = internalLocked{}
var _ ClientError = internalLocked{} var _ ClientError = internalLocked{}
var _ Locked = internalLocked{} var _ Locked = internalLocked{}
@ -25,8 +29,8 @@ func (receiver internalLocked) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalLocked) ErrHTTP() { func (internalLocked) ErrHTTP() int {
// Nothing here. return http.StatusLocked
} }
func (internalLocked) ClientError() { func (internalLocked) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalLoopDetected{} var _ Error = internalLoopDetected{}
var _ ServerError = internalLoopDetected{} var _ ServerError = internalLoopDetected{}
var _ LoopDetected = internalLoopDetected{} var _ LoopDetected = internalLoopDetected{}
@ -27,8 +31,8 @@ func (receiver internalLoopDetected) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalLoopDetected) ErrHTTP() { func (internalLoopDetected) ErrHTTP() int {
// Nothing here. return http.StatusLoopDetected
} }
func (internalLoopDetected) ServerError() { func (internalLoopDetected) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalMethodNotAllowed{} var _ Error = internalMethodNotAllowed{}
var _ ClientError = internalMethodNotAllowed{} var _ ClientError = internalMethodNotAllowed{}
var _ MethodNotAllowed = internalMethodNotAllowed{} var _ MethodNotAllowed = internalMethodNotAllowed{}
@ -25,8 +29,8 @@ func (receiver internalMethodNotAllowed) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalMethodNotAllowed) ErrHTTP() { func (internalMethodNotAllowed) ErrHTTP() int {
// Nothing here. return http.StatusMethodNotAllowed
} }
func (internalMethodNotAllowed) ClientError() { func (internalMethodNotAllowed) ClientError() {

View File

@ -0,0 +1,46 @@
package errhttp
import (
"net/http"
)
var _ Error = internalMisdirectedRequest{}
var _ ClientError = internalMisdirectedRequest{}
var _ MisdirectedRequest = internalMisdirectedRequest{}
var ErrMisdirectedRequest = MisdirectedRequestWrap(nil)
type MisdirectedRequest interface {
ClientError
MisdirectedRequest()
}
type internalMisdirectedRequest struct {
err error
}
func MisdirectedRequestWrap(err error) error {
return internalMisdirectedRequest{
err:err,
}
}
func (receiver internalMisdirectedRequest) Error() string {
return receiver.err.Error()
}
func (internalMisdirectedRequest) ErrHTTP() int {
return http.StatusMisdirectedRequest
}
func (internalMisdirectedRequest) ClientError() {
// Nothing here.
}
func (internalMisdirectedRequest) MisdirectedRequest() {
// Nothing here.
}
func (receiver internalMisdirectedRequest) Unwrap() error {
return receiver.err
}

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalNetworkAuthenticationRequired{} var _ Error = internalNetworkAuthenticationRequired{}
var _ ServerError = internalNetworkAuthenticationRequired{} var _ ServerError = internalNetworkAuthenticationRequired{}
var _ NetworkAuthenticationRequired = internalNetworkAuthenticationRequired{} var _ NetworkAuthenticationRequired = internalNetworkAuthenticationRequired{}
@ -27,8 +31,8 @@ func (receiver internalNetworkAuthenticationRequired) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalNetworkAuthenticationRequired) ErrHTTP() { func (internalNetworkAuthenticationRequired) ErrHTTP() int {
// Nothing here. return http.StatusNetworkAuthenticationRequired
} }
func (internalNetworkAuthenticationRequired) ServerError() { func (internalNetworkAuthenticationRequired) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalNotAcceptable{} var _ Error = internalNotAcceptable{}
var _ ClientError = internalNotAcceptable{} var _ ClientError = internalNotAcceptable{}
var _ NotAcceptable = internalNotAcceptable{} var _ NotAcceptable = internalNotAcceptable{}
@ -25,8 +29,8 @@ func (receiver internalNotAcceptable) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalNotAcceptable) ErrHTTP() { func (internalNotAcceptable) ErrHTTP() int {
// Nothing here. return http.StatusNotAcceptable
} }
func (internalNotAcceptable) ClientError() { func (internalNotAcceptable) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalNotExtended{} var _ Error = internalNotExtended{}
var _ ServerError = internalNotExtended{} var _ ServerError = internalNotExtended{}
var _ NotExtended = internalNotExtended{} var _ NotExtended = internalNotExtended{}
@ -27,8 +31,8 @@ func (receiver internalNotExtended) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalNotExtended) ErrHTTP() { func (internalNotExtended) ErrHTTP() int {
// Nothing here. return http.StatusNotExtended
} }
func (internalNotExtended) ServerError() { func (internalNotExtended) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalNotFound{} var _ Error = internalNotFound{}
var _ ClientError = internalNotFound{} var _ ClientError = internalNotFound{}
var _ NotFound = internalNotFound{} var _ NotFound = internalNotFound{}
@ -25,8 +29,8 @@ func (receiver internalNotFound ) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalNotFound ) ErrHTTP() { func (internalNotFound ) ErrHTTP() int {
// Nothing here. return http.StatusNotFound
} }
func (internalNotFound ) ClientError() { func (internalNotFound ) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalNotImplemented{} var _ Error = internalNotImplemented{}
var _ ServerError = internalNotImplemented{} var _ ServerError = internalNotImplemented{}
var _ NotImplemented = internalNotImplemented{} var _ NotImplemented = internalNotImplemented{}
@ -27,8 +31,8 @@ func (receiver internalNotImplemented) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalNotImplemented) ErrHTTP() { func (internalNotImplemented) ErrHTTP() int {
// Nothing here. return http.StatusNotImplemented
} }
func (internalNotImplemented) ServerError() { func (internalNotImplemented) ServerError() {

View File

@ -1,42 +0,0 @@
package errhttp
var _ Error = internalPayloadTooLarge{}
var _ ClientError = internalPayloadTooLarge{}
var _ PayloadTooLarge = internalPayloadTooLarge{}
var ErrPayloadTooLarge error = PayloadTooLargeWrap(nil)
type PayloadTooLarge interface {
ClientError
PayloadTooLarge()
}
type internalPayloadTooLarge struct {
err error
}
func PayloadTooLargeWrap(err error) error {
return internalPayloadTooLarge{
err:err,
}
}
func (receiver internalPayloadTooLarge) Error() string {
return receiver.err.Error()
}
func (internalPayloadTooLarge) ErrHTTP() {
// Nothing here.
}
func (internalPayloadTooLarge) ClientError() {
// Nothing here.
}
func (internalPayloadTooLarge) PayloadTooLarge() {
// Nothing here.
}
func (receiver internalPayloadTooLarge) Unwrap() error {
return receiver.err
}

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalPaymentRequired{} var _ Error = internalPaymentRequired{}
var _ ClientError = internalPaymentRequired{} var _ ClientError = internalPaymentRequired{}
var _ PaymentRequired = internalPaymentRequired{} var _ PaymentRequired = internalPaymentRequired{}
@ -25,8 +29,8 @@ func (receiver internalPaymentRequired) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalPaymentRequired) ErrHTTP() { func (internalPaymentRequired) ErrHTTP() int {
// Nothing here. return http.StatusPaymentRequired
} }

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalPreconditionFailed{} var _ Error = internalPreconditionFailed{}
var _ ClientError = internalPreconditionFailed{} var _ ClientError = internalPreconditionFailed{}
var _ PreconditionFailed = internalPreconditionFailed{} var _ PreconditionFailed = internalPreconditionFailed{}
@ -25,8 +29,8 @@ func (receiver internalPreconditionFailed) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalPreconditionFailed) ErrHTTP() { func (internalPreconditionFailed) ErrHTTP() int {
// Nothing here. return http.StatusPreconditionFailed
} }
func (internalPreconditionFailed) ClientError() { func (internalPreconditionFailed) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalPreconditionRequired{} var _ Error = internalPreconditionRequired{}
var _ ClientError = internalPreconditionRequired{} var _ ClientError = internalPreconditionRequired{}
var _ PreconditionRequired = internalPreconditionRequired{} var _ PreconditionRequired = internalPreconditionRequired{}
@ -25,8 +29,8 @@ func (receiver internalPreconditionRequired) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalPreconditionRequired) ErrHTTP() { func (internalPreconditionRequired) ErrHTTP() int {
// Nothing here. return http.StatusPreconditionRequired
} }
func (internalPreconditionRequired) ClientError() { func (internalPreconditionRequired) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalProxyAuthRequired{} var _ Error = internalProxyAuthRequired{}
var _ ClientError = internalProxyAuthRequired{} var _ ClientError = internalProxyAuthRequired{}
var _ ProxyAuthRequired = internalProxyAuthRequired{} var _ ProxyAuthRequired = internalProxyAuthRequired{}
@ -25,8 +29,8 @@ func (receiver internalProxyAuthRequired) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalProxyAuthRequired) ErrHTTP() { func (internalProxyAuthRequired) ErrHTTP() int {
// Nothing here. return http.StatusProxyAuthRequired
} }
func (internalProxyAuthRequired) ClientError() { func (internalProxyAuthRequired) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalRequestedRangeNotSatisfiable{} var _ Error = internalRequestedRangeNotSatisfiable{}
var _ ClientError = internalRequestedRangeNotSatisfiable{} var _ ClientError = internalRequestedRangeNotSatisfiable{}
var _ RequestedRangeNotSatisfiable = internalRequestedRangeNotSatisfiable{} var _ RequestedRangeNotSatisfiable = internalRequestedRangeNotSatisfiable{}
@ -25,8 +29,8 @@ func (receiver internalRequestedRangeNotSatisfiable) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalRequestedRangeNotSatisfiable) ErrHTTP() { func (internalRequestedRangeNotSatisfiable) ErrHTTP() int {
// Nothing here. return http.StatusRequestedRangeNotSatisfiable
} }
func (internalRequestedRangeNotSatisfiable) ClientError() { func (internalRequestedRangeNotSatisfiable) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalRequestEntityTooLarge{} var _ Error = internalRequestEntityTooLarge{}
var _ ClientError = internalRequestEntityTooLarge{} var _ ClientError = internalRequestEntityTooLarge{}
var _ RequestEntityTooLarge = internalRequestEntityTooLarge{} var _ RequestEntityTooLarge = internalRequestEntityTooLarge{}
@ -25,8 +29,8 @@ func (receiver internalRequestEntityTooLarge) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalRequestEntityTooLarge) ErrHTTP() { func (internalRequestEntityTooLarge) ErrHTTP() int {
// Nothing here. return http.StatusRequestEntityTooLarge
} }
func (internalRequestEntityTooLarge) ClientError() { func (internalRequestEntityTooLarge) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalRequestHeaderFieldsTooLarge{} var _ Error = internalRequestHeaderFieldsTooLarge{}
var _ ClientError = internalRequestHeaderFieldsTooLarge{} var _ ClientError = internalRequestHeaderFieldsTooLarge{}
var _ RequestHeaderFieldsTooLarge = internalRequestHeaderFieldsTooLarge{} var _ RequestHeaderFieldsTooLarge = internalRequestHeaderFieldsTooLarge{}
@ -25,8 +29,8 @@ func (receiver internalRequestHeaderFieldsTooLarge) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalRequestHeaderFieldsTooLarge) ErrHTTP() { func (internalRequestHeaderFieldsTooLarge) ErrHTTP() int {
// Nothing here. return http.StatusRequestHeaderFieldsTooLarge
} }
func (internalRequestHeaderFieldsTooLarge) ClientError() { func (internalRequestHeaderFieldsTooLarge) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalRequestTimeout{} var _ Error = internalRequestTimeout{}
var _ ClientError = internalRequestTimeout{} var _ ClientError = internalRequestTimeout{}
var _ RequestTimeout = internalRequestTimeout{} var _ RequestTimeout = internalRequestTimeout{}
@ -25,8 +29,8 @@ func (receiver internalRequestTimeout) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalRequestTimeout) ErrHTTP() { func (internalRequestTimeout) ErrHTTP() int {
// Nothing here. return http.StatusRequestTimeout
} }
func (internalRequestTimeout) ClientError() { func (internalRequestTimeout) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalRequestURITooLong{} var _ Error = internalRequestURITooLong{}
var _ ClientError = internalRequestURITooLong{} var _ ClientError = internalRequestURITooLong{}
var _ RequestURITooLong = internalRequestURITooLong{} var _ RequestURITooLong = internalRequestURITooLong{}
@ -25,8 +29,8 @@ func (receiver internalRequestURITooLong) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalRequestURITooLong) ErrHTTP() { func (internalRequestURITooLong) ErrHTTP() int {
// Nothing here. return http.StatusRequestURITooLong
} }
func (internalRequestURITooLong) ClientError() { func (internalRequestURITooLong) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalServiceUnavailable{} var _ Error = internalServiceUnavailable{}
var _ ServerError = internalServiceUnavailable{} var _ ServerError = internalServiceUnavailable{}
var _ ServiceUnavailable = internalServiceUnavailable{} var _ ServiceUnavailable = internalServiceUnavailable{}
@ -25,8 +29,8 @@ func (receiver internalServiceUnavailable) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalServiceUnavailable) ErrHTTP() { func (internalServiceUnavailable) ErrHTTP() int {
// Nothing here. return http.StatusServiceUnavailable
} }
func (internalServiceUnavailable) ServerError() { func (internalServiceUnavailable) ServerError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalTeapot{} var _ Error = internalTeapot{}
var _ ClientError = internalTeapot{} var _ ClientError = internalTeapot{}
var _ Teapot = internalTeapot{} var _ Teapot = internalTeapot{}
@ -25,8 +29,8 @@ func (receiver internalTeapot) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalTeapot) ErrHTTP() { func (internalTeapot) ErrHTTP() int {
// Nothing here. return http.StatusTeapot
} }
func (internalTeapot) ClientError() { func (internalTeapot) ClientError() {

46
tooearly.go 100644
View File

@ -0,0 +1,46 @@
package errhttp
import (
"net/http"
)
var _ Error = internalTooEarly{}
var _ ClientError = internalTooEarly{}
var _ TooEarly = internalTooEarly{}
var ErrTooEarly = TooEarlyWrap(nil)
type TooEarly interface {
ClientError
TooEarly()
}
type internalTooEarly struct {
err error
}
func TooEarlyWrap(err error) error {
return internalTooEarly{
err:err,
}
}
func (receiver internalTooEarly) Error() string {
return receiver.err.Error()
}
func (internalTooEarly) ErrHTTP() int {
return http.StatusTooEarly
}
func (internalTooEarly) ClientError() {
// Nothing here.
}
func (internalTooEarly) TooEarly() {
// Nothing here.
}
func (receiver internalTooEarly) Unwrap() error {
return receiver.err
}

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalTooManyRequests{} var _ Error = internalTooManyRequests{}
var _ ClientError = internalTooManyRequests{} var _ ClientError = internalTooManyRequests{}
var _ TooManyRequests = internalTooManyRequests{} var _ TooManyRequests = internalTooManyRequests{}
@ -25,8 +29,8 @@ func (receiver internalTooManyRequests) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalTooManyRequests) ErrHTTP() { func (internalTooManyRequests) ErrHTTP() int {
// Nothing here. return http.StatusTooManyRequests
} }
func (internalTooManyRequests) ClientError() { func (internalTooManyRequests) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalUnauthorized{} var _ Error = internalUnauthorized{}
var _ ClientError = internalUnauthorized{} var _ ClientError = internalUnauthorized{}
var _ Unauthorized = internalUnauthorized{} var _ Unauthorized = internalUnauthorized{}
@ -25,8 +29,8 @@ func (receiver internalUnauthorized) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalUnauthorized) ErrHTTP() { func (internalUnauthorized) ErrHTTP() int {
// Nothing here. return http.StatusUnauthorized
} }
func (internalUnauthorized) ClientError() { func (internalUnauthorized) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalUnavailableForLegalReasons{} var _ Error = internalUnavailableForLegalReasons{}
var _ ClientError = internalUnavailableForLegalReasons{} var _ ClientError = internalUnavailableForLegalReasons{}
var _ UnavailableForLegalReasons = internalUnavailableForLegalReasons{} var _ UnavailableForLegalReasons = internalUnavailableForLegalReasons{}
@ -25,8 +29,8 @@ func (receiver internalUnavailableForLegalReasons) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalUnavailableForLegalReasons) ErrHTTP() { func (internalUnavailableForLegalReasons) ErrHTTP() int {
// Nothing here. return http.StatusUnavailableForLegalReasons
} }
func (internalUnavailableForLegalReasons) ClientError() { func (internalUnavailableForLegalReasons) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalUnprocessableEntity{} var _ Error = internalUnprocessableEntity{}
var _ ClientError = internalUnprocessableEntity{} var _ ClientError = internalUnprocessableEntity{}
var _ UnprocessableEntity = internalUnprocessableEntity{} var _ UnprocessableEntity = internalUnprocessableEntity{}
@ -25,8 +29,8 @@ func (receiver internalUnprocessableEntity) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalUnprocessableEntity) ErrHTTP() { func (internalUnprocessableEntity) ErrHTTP() int {
// Nothing here. return http.StatusUnprocessableEntity
} }
func (internalUnprocessableEntity) ClientError() { func (internalUnprocessableEntity) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalUnsupportedMediaType{} var _ Error = internalUnsupportedMediaType{}
var _ ClientError = internalUnsupportedMediaType{} var _ ClientError = internalUnsupportedMediaType{}
var _ UnsupportedMediaType = internalUnsupportedMediaType{} var _ UnsupportedMediaType = internalUnsupportedMediaType{}
@ -25,8 +29,8 @@ func (receiver internalUnsupportedMediaType) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalUnsupportedMediaType) ErrHTTP() { func (internalUnsupportedMediaType) ErrHTTP() int {
// Nothing here. return http.StatusUnsupportedMediaType
} }
func (internalUnsupportedMediaType) ClientError() { func (internalUnsupportedMediaType) ClientError() {

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalUpgradeRequired{} var _ Error = internalUpgradeRequired{}
var _ ClientError = internalUpgradeRequired{} var _ ClientError = internalUpgradeRequired{}
var _ UpgradeRequired = internalUpgradeRequired{} var _ UpgradeRequired = internalUpgradeRequired{}
@ -25,8 +29,8 @@ func (receiver internalUpgradeRequired) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalUpgradeRequired) ErrHTTP() { func (internalUpgradeRequired) ErrHTTP() int {
// Nothing here. return http.StatusUpgradeRequired
} }
func (internalUpgradeRequired) ClientError() { func (internalUpgradeRequired) ClientError() {

View File

@ -1,42 +0,0 @@
package errhttp
var _ Error = internalURITooLong{}
var _ ClientError = internalURITooLong{}
var _ URITooLong = internalURITooLong{}
var ErrURITooLong error = URITooLongWrap(nil)
type URITooLong interface {
ClientError
URITooLong()
}
type internalURITooLong struct {
err error
}
func URITooLongWrap(err error) error {
return internalURITooLong{
err:err,
}
}
func (receiver internalURITooLong) Error() string {
return receiver.err.Error()
}
func (internalURITooLong) ErrHTTP() {
// Nothing here.
}
func (internalURITooLong) ClientError() {
// Nothing here.
}
func (internalURITooLong) URITooLong() {
// Nothing here.
}
func (receiver internalURITooLong) Unwrap() error {
return receiver.err
}

View File

@ -1,5 +1,9 @@
package errhttp package errhttp
import (
"net/http"
)
var _ Error = internalVariantAlsoNegotiates{} var _ Error = internalVariantAlsoNegotiates{}
var _ ServerError = internalVariantAlsoNegotiates{} var _ ServerError = internalVariantAlsoNegotiates{}
var _ VariantAlsoNegotiates = internalVariantAlsoNegotiates{} var _ VariantAlsoNegotiates = internalVariantAlsoNegotiates{}
@ -27,8 +31,8 @@ func (receiver internalVariantAlsoNegotiates) Error() string {
return receiver.err.Error() return receiver.err.Error()
} }
func (internalVariantAlsoNegotiates) ErrHTTP() { func (internalVariantAlsoNegotiates) ErrHTTP() int {
// Nothing here. return http.StatusVariantAlsoNegotiates
} }
func (internalVariantAlsoNegotiates) ServerError() { func (internalVariantAlsoNegotiates) ServerError() {