Added logic to handle HTTP 400: Bad Request errors.