Login Error Handling and Cleanup

Add some handling for login errors. Set up a custom exception for
catching this. Adjusted the logging a bit and adjusted how errors are
handled in main.