Handle security exceptions

Handle security exceptions by returning 401 or 403 errors