Write the error in the response

This commit is contained in:
Alfred Kamanda 2024-12-11 18:58:50 +03:00
parent 43892f0d8c
commit 5d8de80a18
Signed by: Alfred-mk
GPG Key ID: 7EA3D01708908703

View File

@ -17,8 +17,7 @@ var (
type DefaultRequestParser struct { type DefaultRequestParser struct {
} }
func (rp *DefaultRequestParser) GetSessionId(rq any) (string, error) {
func(rp *DefaultRequestParser) GetSessionId(rq any) (string, error) {
rqv, ok := rq.(*http.Request) rqv, ok := rq.(*http.Request)
if !ok { if !ok {
return "", handlers.ErrInvalidRequest return "", handlers.ErrInvalidRequest
@ -30,7 +29,7 @@ func(rp *DefaultRequestParser) GetSessionId(rq any) (string, error) {
return v, nil return v, nil
} }
func(rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) { func (rp *DefaultRequestParser) GetInput(rq any) ([]byte, error) {
rqv, ok := rq.(*http.Request) rqv, ok := rq.(*http.Request)
if !ok { if !ok {
return nil, handlers.ErrInvalidRequest return nil, handlers.ErrInvalidRequest
@ -53,19 +52,18 @@ func ToSessionHandler(h handlers.RequestHandler) *SessionHandler {
} }
} }
func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) { func (f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) {
s := err.Error() s := err.Error()
w.Header().Set("Content-Length", strconv.Itoa(len(s))) w.Header().Set("Content-Length", strconv.Itoa(len(s)))
w.WriteHeader(code) w.WriteHeader(code)
_, err = w.Write([]byte{}) _, err = w.Write([]byte(s))
if err != nil { if err != nil {
logg.Errorf("error writing error!!", "err", err, "olderr", s) logg.Errorf("error writing error!!", "err", err, "olderr", s)
w.WriteHeader(500) w.WriteHeader(500)
} }
return
} }
func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { func (f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
var code int var code int
var err error var err error
var perr error var perr error