Updated error output to return status code and be formatted as HTML.Added error handling logic to authcode.