1
0
mirror of https://github.com/labstack/echo.git synced 2026-05-16 09:48:24 +02:00

chore: fix typos in httperror.go

Signed-off-by: tison <wander4096@gmail.com>
This commit is contained in:
tison
2026-04-27 22:07:34 +08:00
parent d1d8ad3f99
commit 86d0223c7a
+9 -9
View File
@@ -9,7 +9,7 @@ import (
"net/http" "net/http"
) )
// Following errors can produce HTTP status code by implementing HTTPStatusCoder interface // The following errors can produce HTTP status code by implementing HTTPStatusCoder interface
var ( var (
ErrBadRequest = &httpError{http.StatusBadRequest} // 400 ErrBadRequest = &httpError{http.StatusBadRequest} // 400
ErrUnauthorized = &httpError{http.StatusUnauthorized} // 401 ErrUnauthorized = &httpError{http.StatusUnauthorized} // 401
@@ -25,7 +25,7 @@ var (
ErrServiceUnavailable = &httpError{http.StatusServiceUnavailable} // 503 ErrServiceUnavailable = &httpError{http.StatusServiceUnavailable} // 503
) )
// Following errors fall into 500 (InternalServerError) category // The following errors fall into 500 (InternalServerError) category
var ( var (
ErrValidatorNotRegistered = errors.New("validator not registered") ErrValidatorNotRegistered = errors.New("validator not registered")
ErrRendererNotRegistered = errors.New("renderer not registered") ErrRendererNotRegistered = errors.New("renderer not registered")
@@ -35,13 +35,13 @@ var (
ErrInvalidListenerNetwork = errors.New("invalid listener network") ErrInvalidListenerNetwork = errors.New("invalid listener network")
) )
// HTTPStatusCoder is interface that errors can implement to produce status code for HTTP response // HTTPStatusCoder is an interface that errors can implement to produce status code for HTTP response
type HTTPStatusCoder interface { type HTTPStatusCoder interface {
StatusCode() int StatusCode() int
} }
// StatusCode returns status code from error if it implements HTTPStatusCoder interface. // StatusCode returns status code from err if it implements HTTPStatusCoder interface.
// If error does not implement the interface it returns 0. // If err does not implement the interface, it returns 0.
func StatusCode(err error) int { func StatusCode(err error) int {
var sc HTTPStatusCoder var sc HTTPStatusCoder
if errors.As(err, &sc) { if errors.As(err, &sc) {
@@ -95,7 +95,7 @@ func ResolveResponseStatus(rw http.ResponseWriter, err error) (resp *Response, s
return resp, status return resp, status
} }
// NewHTTPError creates new instance of HTTPError // NewHTTPError creates a new instance of HTTPError
func NewHTTPError(code int, message string) *HTTPError { func NewHTTPError(code int, message string) *HTTPError {
return &HTTPError{ return &HTTPError{
Code: code, Code: code,
@@ -116,7 +116,7 @@ func (he *HTTPError) StatusCode() int {
return he.Code return he.Code
} }
// Error makes it compatible with `error` interface. // Error makes it compatible with the ` error ` interface.
func (he *HTTPError) Error() string { func (he *HTTPError) Error() string {
msg := he.Message msg := he.Message
if msg == "" { if msg == "" {
@@ -128,8 +128,8 @@ func (he *HTTPError) Error() string {
return fmt.Sprintf("code=%d, message=%v, err=%v", he.Code, msg, he.err.Error()) return fmt.Sprintf("code=%d, message=%v, err=%v", he.Code, msg, he.err.Error())
} }
// Wrap eturns new HTTPError with given errors wrapped inside // Wrap returns a new HTTPError with given errors wrapped inside
func (he HTTPError) Wrap(err error) error { func (he *HTTPError) Wrap(err error) error {
return &HTTPError{ return &HTTPError{
Code: he.Code, Code: he.Code,
Message: he.Message, Message: he.Message,