Fix #2217 - handling exceptions with authentication