form Class, add a check function before the buildForm method
You can do all that inside of buildForm():

use Symfony\Component\HttpKernel\Exception\HttpException;

public function buildForm(array $form, FormStateInterface $form_state) {

  $data = a_check_function_or_method_before_buildForm();

  // throw an exception
  if (empty($data)) {
    throw new HttpException(500, 'No data connection.');
  }

  // or return an empty form with an error message
  if (empty($data)) {
    return $form['#markup'] = '&lt;h1&gt;No data could be collected!&lt;/h1&gt;';
  }

  // build the form with $data

}


Another possibility would be to call first a controller, which then decides what to do, return a form or something else.