Error
builtin errors
内置的错误变量
var ( ErrUnsupportedMediaType = NewHTTPError(http.StatusUnsupportedMediaType) ErrNotFound = NewHTTPError(http.StatusNotFound) ErrUnauthorized = NewHTTPError(http.StatusUnauthorized) ErrForbidden = NewHTTPError(http.StatusForbidden) ErrMethodNotAllowed = NewHTTPError(http.StatusMethodNotAllowed) ErrStatusRequestEntityTooLarge = NewHTTPError(http.StatusRequestEntityTooLarge) ErrTooManyRequests = NewHTTPError(http.StatusTooManyRequests) ErrBadRequest = NewHTTPError(http.StatusBadRequest) ErrBadGateway = NewHTTPError(http.StatusBadGateway) ErrInternalServerError = NewHTTPError(http.StatusInternalServerError) ErrRequestTimeout = NewHTTPError(http.StatusRequestTimeout) ErrServiceUnavailable = NewHTTPError(http.StatusServiceUnavailable) ErrValidatorNotRegistered = errors.New("slim: validator not registered") ErrRendererNotRegistered = errors.New("slim: renderer not registered") ErrInvalidRedirectCode = errors.New("slim: invalid redirect status code") ErrCookieNotFound = errors.New("slim: cookie not found") ErrInvalidCertOrKeyType = errors.New("slim: invalid cert or key type, must be string or []byte") ErrInvalidListenerNetwork = errors.New("slim: invalid listener network") ErrFilesystemNotRegistered = errors.New("slim: filesystem not registered"))func NewHTTPError
func NewHTTPError(code int, message ...any) *HTTPError创建一个 HTTP 错误实例。
func NewHTTPErrorWithInternal
func NewHTTPErrorWithInternal(code int, internalError error, message ...any) *HTTPError创建一个包含内部异常的 HTTP 错误实例。
type HTTPError
// HTTPError represents an error that occurred while handling a request.type HTTPError struct { Code int `json:"-"` Message any `json:"message"` Internal error `json:"-"` // Stores the error returned by an external dependency}HTTP 错误结构体,表示在处理请求时发生的错误。
func (*HTTPError) Error
func (he *HTTPError) Error() string实现 error 接口。
func (*HTTPError) WithInternal
func (he *HTTPError) WithInternal(err error) *HTTPError复制当前实例并设置内部异常。
func (*HTTPError) Unwrap
func (he *HTTPError) Unwrap() error实现错误包装器接口。