Fixed exception handling for invalid authentication.
unit test improvements.