I have created a REST API server using go-swagger and added bearer token security to a few endpoints. As per docs, the token verification method should have a signature like func(string) (interface{}, error)
.
The token verification method returns an error if the passed bearer token is not valid. This results in 500 responses to the requestor with JSON response body:
{
"code": 500,
"message": "Token is expired"
}
However, as standers how can I make this response with code 401.
Note: A similar discussion like this for Java can be found at https://stackoverflow.com/a/60738107/16087692 , Is there any way to achieve this Go?