public function returnError($errorKeyOrDefinition, $replacementArray = array()) {
    if (is_string($errorKeyOrDefinition)) {
      $errorKey = $errorKeyOrDefinition;
    }
    else {
      $errorKeys = array_keys($errorKeyOrDefinition);
      $errorKey = $errorKeys[0];
    }

    $errorResponse = $this->errorResponseDictionary->getErrorResponse($errorKey);
    if (empty($errorResponse)) {
      $errorResponse = ErrorResponse::FromArray($errorKeyOrDefinition[$errorKey]);
    }

    $appCode = $errorResponse->getCode();
    echo json_encode(array(
      'error' => empty($appCode) ? array('message' => $errorResponse->getFormattedMessage($replacementArray)) :
          array('code' => $appCode, 'message' => $errorResponse->getFormattedMessage($replacementArray))
    ));
    $this->getResponse()->status($errorResponse->getHttpcode());
    throw new Stop($errorResponse->getFormattedMessage($replacementArray));
  }