Skip to content

Commit

Permalink
Added ResponseErrorWriter interface to allow for custom error json ma…
Browse files Browse the repository at this point in the history
…rshalling
  • Loading branch information
Keith Ball committed Jul 27, 2015
1 parent 4deeabb commit 80565de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
5 changes: 1 addition & 4 deletions method_not_allowed.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ func (h MethodNotAllowedHandler) ServeHTTP(w http.ResponseWriter, r *http.Reques
strings.Join(methods, ", "),
)
if acceptJSON(r) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusMethodNotAllowed)
err := MethodNotAllowed{Err: errors.New(description)}
ResponseErrorWriter.WriteJSONError(w, err)
ResponseErrorWriter.WriteJSONError(w, MethodNotAllowed{Err: errors.New(description)})
} else {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusMethodNotAllowed)
Expand Down
5 changes: 1 addition & 4 deletions not_found.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ type NotFoundHandler struct{}
func (NotFoundHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
description := fmt.Sprintf("%s %s not found", r.Method, r.URL.Path)
if acceptJSON(r) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusNotFound)
err := NotFound{Err: errors.New(description)}
ResponseErrorWriter.WriteJSONError(w, err)
ResponseErrorWriter.WriteJSONError(w, NotFound{Err: errors.New(description)})
} else {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusNotFound)
Expand Down

0 comments on commit 80565de

Please sign in to comment.