Improved error handling
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"git.akyoto.dev/go/router"
|
||||
@ -34,7 +35,7 @@ func (server *Server) ServeHTTP(response http.ResponseWriter, request *http.Requ
|
||||
|
||||
if handler == nil {
|
||||
response.WriteHeader(http.StatusNotFound)
|
||||
fmt.Fprint(response, http.StatusText(http.StatusNotFound))
|
||||
response.(io.StringWriter).WriteString(http.StatusText(http.StatusNotFound))
|
||||
contextPool.Put(ctx)
|
||||
return
|
||||
}
|
||||
@ -42,7 +43,8 @@ func (server *Server) ServeHTTP(response http.ResponseWriter, request *http.Requ
|
||||
err := handler(ctx)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprint(response, err.Error())
|
||||
response.(io.StringWriter).WriteString(err.Error())
|
||||
log.Println(request.URL, err)
|
||||
}
|
||||
|
||||
contextPool.Put(ctx)
|
||||
|
Reference in New Issue
Block a user