make HTTP error an interface
1 file changed, 5 insertions(+), 5 deletions(-)
changed files
M shared/http/mux.go → shared/http/mux.go
@@ -7,15 +7,15 @@ "alin.ovh/x/log" ) // HandleFunc is a function that handles an HTTP request and may return an Error. -type HandleFunc func(http.ResponseWriter, *http.Request) *Error +type HandleFunc func(http.ResponseWriter, *http.Request) Error // Handler is an interface for types that can serve HTTP requests and may return an Error. type Handler interface { - ServeHTTP(http.ResponseWriter, *http.Request) *Error + ServeHTTP(http.ResponseWriter, *http.Request) Error } // ErrorHandler is a function that handles HTTP errors. -type ErrorHandler func(*Error, http.ResponseWriter, *http.Request) +type ErrorHandler func(Error, http.ResponseWriter, *http.Request) // ServeMux is an HTTP request multiplexer with error handling support. // It matches the URL of each incoming request against a list of registered@@ -30,8 +30,8 @@ // NewServeMux creates a new ServeMux with a default error handler. func NewServeMux() *ServeMux { return &ServeMux{ ServeMux: http.NewServeMux(), - errorHandler: func(err *Error, w http.ResponseWriter, _ *http.Request) { - http.Error(w, err.Message, err.Code) + errorHandler: func(err Error, w http.ResponseWriter, _ *http.Request) { + err.WriteHTTP(w) }, } }