pkg/interceptor/errror.go (24 lines of code) (raw):

package interceptor import ( "net/http" ) // Error represents a handler error. It provides methods for an HTTP status // code and embeds the built-in error interface. type Error interface { error Status() int } // HTTPError represents an error with an associated HTTP status code. type HTTPError struct { Code int Err error } // HTTPError allows to satisfy the error interface. func (se HTTPError) Error() string { return se.Err.Error() } // Status returns our HTTP status code. func (se HTTPError) Status() int { return se.Code } func badRequest(err error) HTTPError { return HTTPError{Code: http.StatusBadRequest, Err: err} } func internal(err error) HTTPError { return HTTPError{Code: http.StatusInternalServerError, Err: err} }