diff --git a/context.go b/context.go index cf6c73d..60ab4df 100644 --- a/context.go +++ b/context.go @@ -35,6 +35,11 @@ func (c *Context) String(code int, s string) error { return err } +// StatusText returns the given status code with the matching status text +func (c *Context) StatusText(code int) error { + return c.String(code, http.StatusText(code)) +} + // NoContent returns the given status code without writing anything to the body func (c *Context) NoContent(code int) error { c.Response.WriteHeader(code) diff --git a/default.go b/default.go index 2f0aeac..d36c6c8 100644 --- a/default.go +++ b/default.go @@ -2,20 +2,19 @@ package router import ( "encoding/json" - "fmt" + "net/http" ) func defaultNotFoundHandler(c *Context) error { - return c.String(404, `not found`) + return c.StatusText(http.StatusNotFound) } func defaultMethodNotAllowedHandler(c *Context) error { - return c.String(504, `method not allowed`) + return c.StatusText(http.StatusMethodNotAllowed) } func defaultErrorHandler(c *Context, err interface{}) { - fmt.Println(err) - c.String(500, `internal server error`) + _ = c.StatusText(http.StatusInternalServerError) } func defaultReader(c *Context, dst interface{}) bool {