mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add NotFound and MethodNotAllowed routes
This commit is contained in:
parent
a72bb0b066
commit
661a30542b
2 changed files with 9 additions and 3 deletions
|
@ -12,9 +12,7 @@ func (app *application) serverErrorResponse(w http.ResponseWriter, r *http.Reque
|
|||
app.errorResponse(w, r, http.StatusInternalServerError, message)
|
||||
}
|
||||
|
||||
// The logError() method is a generic helper for logging an error message. Later in the
|
||||
// book we'll upgrade this to use structured logging, and record additional information
|
||||
// about the request including the HTTP method and URL.
|
||||
// The logError() method is a generic helper for logging an error message.
|
||||
func (app *application) logError(r *http.Request, err error) {
|
||||
app.Logger.Errorw("Error",
|
||||
"Request URI", r.RequestURI,
|
||||
|
@ -43,3 +41,8 @@ func (app *application) editConflictResponse(w http.ResponseWriter, r *http.Requ
|
|||
message := "unable to update the record due to an edit conflict, please try again"
|
||||
app.errorResponse(w, r, http.StatusConflict, message)
|
||||
}
|
||||
|
||||
func (app *application) methodNotAllowedResponse(w http.ResponseWriter, r *http.Request) {
|
||||
message := fmt.Sprintf("the %s method is not supported for this resource", r.Method)
|
||||
app.errorResponse(w, r, http.StatusMethodNotAllowed, message)
|
||||
}
|
||||
|
|
|
@ -9,6 +9,9 @@ import (
|
|||
func (app *application) routes() *httprouter.Router {
|
||||
router := httprouter.New()
|
||||
|
||||
router.NotFound = http.HandlerFunc(app.notFoundResponse)
|
||||
router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowedResponse)
|
||||
|
||||
router.HandlerFunc(http.MethodGet, "/v1/commands/:name", app.showCommandHandler)
|
||||
router.HandlerFunc(http.MethodPost, "/v1/commands", app.createCommandHandler)
|
||||
router.HandlerFunc(http.MethodPatch, "/v1/commands/:name", app.updateCommandHandler)
|
||||
|
|
Loading…
Reference in a new issue