cmd/noxy: respond with appropriate status 5xx on context errors

master
alex 2 years ago
parent d2f212f499
commit 1ddf35e212
Signed by: x1ddos
GPG Key ID: FDEFB4A63CBD8460

@ -1,6 +1,7 @@
package main
import (
"context"
"encoding/json"
"errors"
"flag"
@ -197,6 +198,8 @@ func writeError(w http.ResponseWriter, err error) {
w.WriteHeader(http.StatusBadRequest)
case errors.Is(err, noxy.ErrNotFound):
w.WriteHeader(http.StatusNotFound)
case errors.Is(err, context.DeadlineExceeded) || errors.Is(err, context.Canceled):
w.WriteHeader(http.StatusServiceUnavailable)
}
fmt.Fprint(w, err.Error())
}

Loading…
Cancel
Save