How can I change the render of Spring Oauth2 errors? For example when you try to access rest resource which is protected without providing Bearer
header, this error is rendered by Spring Framework :
<oauth>
<error_description>Full authentication is required to access this resource</error_description>
<error>unauthorized</error>
</oauth>
I want it to render like my other API responses and error messages which I am handling with @ControllerAdvice and @ExceptionHandler annotations.
I have tried to provide WebResponseExceptionTranslator but it only triggers when I provide bad credentials.
I see that the DefaultOAuth2ExceptionRenderer
is responsible for rendering this errors, but could not manage to change it.