These are chat archives for gin-gonic/gin

19th
Feb 2019
Dmitriy S. Sinyavskiy
@r3code
Feb 19 10:40
How to handle both error 404 Not Found and 405 Method Not Allowed? I developing REST API and I want my service to handle "Method Not Allowed" if someone does a request with PATCH where only GET allowed.

router := gin.New()
router.NoRoute(notFoundErrorHandler)
router.HandleMethodNotAllowed = true
router.NoMethod(replyWithUnsupportedHTTPMethodError)

func replyWithUnsupportedHTTPMethodError(c *gin.Context) {
c.Error(errors.New("UnsupportedHttpMethod"))
}

func notFoundErrorHandler(c *gin.Context) {
c.Error(errors.New("ErrorResourceNotFound"))
}

Dmitriy S. Sinyavskiy
@r3code
Feb 19 10:48
But if I request with not allowed method it handles it as 404 error and notFoundErrorHandler invoked/
I'm handling errors through middleware
Dmitriy S. Sinyavskiy
@r3code
Feb 19 11:22
Solved. It was browser caching problem ....