I was wondering if I could customize the following authorization error:
{
\"error\": \"unauthorized\",
\"error_description\": \"Full authentication is re
I think you can use @ControllerAdviceto catch the exception unauthorized then format response as your expectation and return it. Something like this:
@ResponseBody
@ExceptionHandler(CustomException.class)
@ResponseStatus(value=HttpStatus.UNAUTHORIZED, reason="Exception message")
public JsonResponse unAuthorised(HttpServletRequest request, Exception ex) {
return new JsonResponse("ERROR", 401, "Unauthorised Request");
}
Hope this help.