Handle authentication errors gracefully and toggle logging. Fixes #2