protected function httpError($errorCode, $message, $exception = null) {
    header("HTTP/1.1 $errorCode $message", true, $errorCode);
    if ($exception) {
      echo json_encode([
        'textStatus' => "$errorCode $message",
        'exception' => get_class($exception),
        'code' => $exception->getCode(),
        'message' => $exception->getMessage()
      ]);
    } else {
      echo json_encode(['textStatus' => "$errorCode $message"]);
    }
    return false;
  }