class Gitlab::QA::Report::GitlabIssueClient

def handle_gitlab_client_exceptions

def handle_gitlab_client_exceptions
  yield
rescue Gitlab::Error::NotFound
  # This error could be raised in assert_user_permission!
  # If so, we want it to terminate at that point
  raise
rescue SystemCallError, OpenSSL::SSL::SSLError, Net::OpenTimeout, Net::ReadTimeout, Gitlab::Error::InternalServerError, Gitlab::Error::Parsing => e
  @retry_backoff += RETRY_BACK_OFF_DELAY
  raise if @retry_backoff > RETRY_BACK_OFF_DELAY * MAX_RETRY_ATTEMPTS
  warn_exception(e)
  warn("Sleeping for #{@retry_backoff} seconds before retrying...")
  sleep @retry_backoff
  retry
rescue StandardError => e
  pipeline = QA::Runtime::Env.pipeline_from_project_name
  channel = pipeline == "canary" ? "qa-production" : "qa-#{pipeline}"
  error_msg = warn_exception(e)
  return unless QA::Runtime::Env.ci_commit_ref_name == QA::Runtime::Env.default_branch
  slack_options = {
    channel: channel,
    icon_emoji: ':ci_failing:',
    message: <<~MSG
      An unexpected error occurred while reporting test results in issues.
      The error occurred in job: #{QA::Runtime::Env.ci_job_url}
      `#{error_msg}`
    MSG
  }
  puts "Posting Slack message to channel: #{channel}"
  Gitlab::QA::Slack::PostToSlack.new(**slack_options).invoke!
end