add more logging and error handling to authorize

fix #1409?