api.redirect
suspends the code flow until the website redirects the user back to the authentication. Otherwise the code flow will not be resumed and the logging will never be triggered.
You can learn more about it here:
The best way to do it would be to use api.access.deny
to send the user to the callback URL and in there you’ll need to process the error and redirect the user to the desired error page.