some logging of 500 errors and fix token and auth code generate bug