Using the new error's helper methods inside our current API endpoint and with our httprouter Handlers NotFound and MethodNotAllowed (will override the default responses with our helper's methods)
All checks were successful
Deploy Greenlight API / deploy (push) Successful in 52s

This commit is contained in:
Maxime Delporte
2025-10-21 19:02:42 +02:00
parent 0f7515e198
commit 2124f2f882
3 changed files with 12 additions and 5 deletions

View File

@@ -9,6 +9,12 @@ func (app *application) routes() http.Handler {
// Initialize a new httprouter router instance
router := httprouter.New()
// Convert the notFoundResponse() helper to a http.Handler using the http.HandlerFunc() adapter, and then set it as the custom error handler for 404 Not Found responses.
router.NotFound = http.HandlerFunc(app.notFoundResponse)
// Likewise, convert the methodNotAllowedResponse() helper to a http.Handler and set it as the custom error handler for 405 Method Not Allowed responses
router.MethodNotAllowed = http.HandlerFunc(app.methodNotAllowedResponse)
/*
Register the relevant methods, URL patterns and handler functions for our
endpoints using the HandlerFunc() method. Note that http.MethodGet and