Skip to content

Commit

Permalink
Improve error BadRequest messages
Browse files Browse the repository at this point in the history
  • Loading branch information
VojtechVitek authored Aug 19, 2024
1 parent 63ec3bf commit 6ff743e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ func (s *{{$serviceName}}) ServeHTTP(w http.ResponseWriter, r *http.Request) {
handler = s.serve{{$method.Name | firstLetterToUpper}}JSON{{if $method.StreamOutput}}Stream{{end}}
{{- end}}
default:
err := ErrWebrpcBadRoute.WithCause(fmt.Errorf("no handler for path %q", r.URL.Path))
err := ErrWebrpcBadRoute.WithCause(fmt.Errorf("no WebRPC method defined for path %v", r.URL.Path))
s.sendErrorJSON(w, r, err)
return
}

if r.Method != "POST" {
w.Header().Add("Allow", "POST") // RFC 9110.
err := ErrWebrpcBadMethod.WithCause(fmt.Errorf("unsupported method %q (only POST is allowed)", r.Method))
err := ErrWebrpcBadMethod.WithCause(fmt.Errorf("unsupported method %v (only POST is allowed)", r.Method))
s.sendErrorJSON(w, r, err)
return
}
Expand All @@ -71,7 +71,7 @@ func (s *{{$serviceName}}) ServeHTTP(w http.ResponseWriter, r *http.Request) {
case "application/json":
handler(ctx, w, r)
default:
err := ErrWebrpcBadRequest.WithCause(fmt.Errorf("unexpected Content-Type: %q", r.Header.Get("Content-Type")))
err := ErrWebrpcBadRequest.WithCause(fmt.Errorf("unsupported Content-Type %q (only application/json is allowed)", r.Header.Get("Content-Type")))
s.sendErrorJSON(w, r, err)
}
}
Expand Down

0 comments on commit 6ff743e

Please sign in to comment.