Repository: apache/airflow
File: airflow-core/src/airflow/ui/src/queries/useTrigger.ts (TypeScript)

Code before:

  const onError = (_error: unknown) => {
    // Check if error is a 403 (Forbidden) status
    if (isHttpError(_error, 403)) {
      toaster.create({
        description: translate(
          "triggerDag.toaster.error.forbidden.description",
          "You don't have permission to trigger this DAG",
        ),
        title: translate("triggerDag.toaster.error.forbidden.title", "Permission Denied"),
        type: "error",
      });
    } else if (isHttpError(_error, 401)) {
      toaster.create({
        description: translate(
          "triggerDag.toaster.error.unauthorized.description",
          "Please log in to trigger DAGs",
        ),
        title: translate("triggerDag.toaster.error.unauthorized.title", "Authentication Required"),
        type: "error",
      });
    } else {
      // Generic error handling for other status codes
      toaster.create({
        description: translate("triggerDag.toaster.error.generic.description", "Failed to trigger DAG"),
        title: translate("triggerDag.toaster.error.generic.title", "Error"),
        type: "error",
      });
    }
    setError(_error);
  };

  const { isPending, mutate } = useDagRunServiceTriggerDagRun({
    onError,
    onSuccess,
  });

  const triggerDagRun = (dagRunRequestBody: DagRunTriggerParams) => {
    const parsedConfig = JSON.parse(dagRunRequestBody.conf) as Record<string, unknown>;

    const logicalDate = dagRunRequestBody.logicalDate ? new Date(dagRunRequestBody.logicalDate) : undefined;

    // eslint-disable-next-line unicorn/no-null
    const formattedLogicalDate = logicalDate?.toISOString() ?? null;

    const checkDagRunId = dagRunRequestBody.dagRunId === "" ? undefined : dagRunRequestBody.dagRunId;
    const checkNote = dagRunRequestBody.note === "" ? undefined : dagRunRequestBody.note;

    mutate({
      dagId,
      requestBody: {

Review comment (suggestion):
You need to add those translation keys to the translation files. Similarly to `triggerDag.toaster.success.title`.

For instance if you check `en/components.json`

Code after:
  const onError = (_error: Error) => {
    toaster.create({
      description: _error.message,
      title: translate("triggerDag.toaster.error.title"),
      type: "error",
    });
    setError(_error);
  };

  const { isPending, mutate } = useDagRunServiceTriggerDagRun({
    onError,
    onSuccess,
  });

  const triggerDagRun = (dagRunRequestBody: DagRunTriggerParams) => {
    const parsedConfig = JSON.parse(dagRunRequestBody.conf) as Record<string, unknown>;

    const logicalDate = dagRunRequestBody.logicalDate ? new Date(dagRunRequestBody.logicalDate) : undefined;

    // eslint-disable-next-line unicorn/no-null
    const formattedLogicalDate = logicalDate?.toISOString() ?? null;

    const checkDagRunId = dagRunRequestBody.dagRunId === "" ? undefined : dagRunRequestBody.dagRunId;
    const checkNote = dagRunRequestBody.note === "" ? undefined : dagRunRequestBody.note;

    mutate({
      dagId,
      requestBody: {
        conf: parsedConfig,
        dag_run_id: checkDagRunId,
        logical_date: formattedLogicalDate,
        note: checkNote,
        partition_key: dagRunRequestBody.partitionKey ?? null,
      },
    });
  };

  return {
    error,
    isPending,
    triggerDagRun,
  };
};