-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #82 from fakefloordiv/dev
Extended status errors, updates in routing resources for more convinience
- Loading branch information
Showing
6 changed files
with
128 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package http | ||
|
||
import ( | ||
"errors" | ||
"github.com/indigo-web/indigo/http/status" | ||
"testing" | ||
) | ||
|
||
func BenchmarkResponse_WithError(b *testing.B) { | ||
resp := NewResponse() | ||
knownErr := status.ErrBadRequest | ||
unknownErr := errors.New("some crap happened, unable to recover") | ||
|
||
b.Run("KnownError", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
resp.WithError(knownErr) | ||
} | ||
}) | ||
|
||
b.Run("UnknownError", func(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
resp.WithError(unknownErr) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,75 @@ | ||
package status | ||
|
||
import ( | ||
"errors" | ||
) | ||
type HTTPError struct { | ||
Code Code | ||
Message string | ||
} | ||
|
||
var ( | ||
ErrBadRequest = errors.New("bad request") | ||
ErrMethodNotImplemented = errors.New("request method is not supported") | ||
ErrTooLarge = errors.New("too large") | ||
ErrHeaderFieldsTooLarge = errors.New("header fields too large") | ||
ErrURITooLong = errors.New("request URI too long") | ||
ErrURIDecoding = errors.New("invalid URI encoding") | ||
ErrBadQuery = errors.New("bad URL query") | ||
ErrUnsupportedProtocol = errors.New("protocol is not supported") | ||
ErrUnsupportedEncoding = errors.New("content encoding is not supported") | ||
ErrTooManyHeaders = errors.New("too many headers") | ||
func newErr(code Code, message string) HTTPError { | ||
return HTTPError{ | ||
Code: code, | ||
Message: message, | ||
} | ||
} | ||
|
||
ErrConnectionTimeout = errors.New("connection timed out") | ||
ErrCloseConnection = errors.New("internal error as a signal") | ||
func (h HTTPError) Error() string { | ||
return h.Message | ||
} | ||
|
||
ErrNotFound = errors.New("not found") | ||
ErrMethodNotAllowed = errors.New("method is not allowed") | ||
ErrInternalServerError = errors.New("internal server error") | ||
var ( | ||
ErrConnectionTimeout = newErr(RequestTimeout, "connection timed out") | ||
ErrCloseConnection = newErr(CloseConnection, "internal error as a signal") | ||
ErrShutdown = newErr(CloseConnection, "graceful shutdown") | ||
|
||
ErrShutdown = errors.New("graceful shutdown") | ||
ErrBadRequest = newErr(BadRequest, "bad request") | ||
ErrNotFound = newErr(NotFound, "not found") | ||
ErrInternalServerError = newErr(InternalServerError, "internal server error") | ||
// ErrMethodNotImplemented is actually uses the same error code as just ErrNotImplemented, but used | ||
// to explain the problem more preciously | ||
ErrMethodNotImplemented = newErr(NotImplemented, "request method is not supported") | ||
ErrMethodNotAllowed = newErr(MethodNotAllowed, "MethodNotAllowed") | ||
ErrTooLarge = newErr(RequestEntityTooLarge, "too large") | ||
ErrHeaderFieldsTooLarge = newErr(RequestHeaderFieldsTooLarge, "header fields too large") | ||
ErrURITooLong = newErr(RequestURITooLong, "request URI too long") | ||
ErrURIDecoding = newErr(BadRequest, "invalid URI encoding") | ||
ErrBadQuery = newErr(BadRequest, "bad URL query") | ||
ErrUnsupportedProtocol = newErr(HTTPVersionNotSupported, "protocol is not supported") | ||
ErrUnsupportedEncoding = newErr(NotAcceptable, "content encoding is not supported") | ||
ErrTooManyHeaders = newErr(RequestHeaderFieldsTooLarge, "too many headers") | ||
ErrUnauthorized = newErr(Unauthorized, "unauthorized") | ||
ErrPaymentRequired = newErr(PaymentRequired, "payment required") | ||
ErrForbidden = newErr(Forbidden, "forbidden") | ||
ErrNotAcceptable = newErr(NotAcceptable, "not acceptable") | ||
ErrProxyAuthRequired = newErr(ProxyAuthRequired, "proxy auth required") | ||
ErrRequestTimeout = newErr(RequestTimeout, "request timeout") | ||
ErrConflict = newErr(Conflict, "conflict") | ||
ErrGone = newErr(Gone, "gone") | ||
ErrLengthRequired = newErr(LengthRequired, "length required") | ||
ErrPreconditionFailed = newErr(PreconditionFailed, "precondition failed") | ||
ErrRequestEntityTooLarge = newErr(RequestEntityTooLarge, "request entity too large") | ||
ErrRequestURITooLong = newErr(RequestURITooLong, "request URI too long") | ||
ErrUnsupportedMediaType = newErr(UnsupportedMediaType, "unsupported media type") | ||
ErrRequestedRangeNotSatisfiable = newErr(RequestedRangeNotSatisfiable, "requested range not satisfiable") | ||
ErrExpectationFailed = newErr(ExpectationFailed, "expectation failed") | ||
ErrTeapot = newErr(Teapot, "i'm a teapot") | ||
ErrMisdirectedRequest = newErr(MisdirectedRequest, "misdirected request") | ||
ErrUnprocessableEntity = newErr(UnprocessableEntity, "unprocessable entity") | ||
ErrLocked = newErr(Locked, "locked") | ||
ErrFailedDependency = newErr(FailedDependency, "failed dependency") | ||
ErrTooEarly = newErr(TooEarly, "too early") | ||
ErrUpgradeRequired = newErr(UpgradeRequired, "upgrade required") | ||
ErrPreconditionRequired = newErr(PreconditionRequired, "precondition required") | ||
ErrTooManyRequests = newErr(TooManyRequests, "too many requests") | ||
ErrRequestHeaderFieldsTooLarge = newErr(RequestHeaderFieldsTooLarge, "request header fields too large") | ||
ErrUnavailableForLegalReasons = newErr(UnavailableForLegalReasons, "unavailable for legal reasons") | ||
ErrNotImplemented = newErr(NotImplemented, "not implemented") | ||
ErrBadGateway = newErr(BadGateway, "bad gateway") | ||
ErrServiceUnavailable = newErr(ServiceUnavailable, "service unavailable") | ||
ErrGatewayTimeout = newErr(GatewayTimeout, "GatewayTimeout") | ||
ErrHTTPVersionNotSupported = newErr(HTTPVersionNotSupported, "HTTP version not supported") | ||
ErrVariantAlsoNegotiates = newErr(VariantAlsoNegotiates, "variant also negotiates") | ||
ErrInsufficientStorage = newErr(InsufficientStorage, "insufficient storage") | ||
ErrLoopDetected = newErr(LoopDetected, "loop detected") | ||
ErrNotExtended = newErr(NotExtended, "not extended") | ||
ErrNetworkAuthenticationRequired = newErr(NetworkAuthenticationRequired, "network authentication required") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.6.0 | ||
0.6.1 |