Improved error handling

This commit is contained in:
2023-07-21 23:23:49 +02:00
parent 7da8fffb90
commit 72ad02a2e2
3 changed files with 33 additions and 8 deletions

View File

@ -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)