Default handlers for NotFound and MethodNotAllowed returning json reason added to control y data servers

This commit is contained in:
Héctor Hurtado
2020-04-07 12:22:15 +02:00
parent 4988c48e03
commit e1788b2874
3 changed files with 33 additions and 4 deletions
+9
View File
@@ -42,6 +42,15 @@ func configRouter(rs []routeSpec) (r *mux.Router) {
func(w http.ResponseWriter, r *http.Request) {
httperror.ErrorJSON(w, "Invalid Resource Path", http.StatusBadRequest)
})
r.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, h *http.Request) {
httperror.ErrorJSON(w, "Data server: Not found", http.StatusNotFound)
})
r.MethodNotAllowedHandler = http.HandlerFunc(func(w http.ResponseWriter, h *http.Request) {
httperror.ErrorJSON(w, "Data server: Method not allowed", http.StatusMethodNotAllowed)
})
return r
}