Removed debug statements.
Added the handling of failure modes BadRequest and Unauthorized.