Improve handling of authentication and authorization errors