Repository: toeverything/AFFiNE
File: packages/frontend/core/src/modules/workspace-indexer-embedding/view/embedding-settings.tsx (TypeScript)

Code before:
  const isIgnoredDocsLoading = useLiveData(
    embeddingService.embedding.isIgnoredDocsLoading$
  );
  const workspaceDialogService = useService(WorkspaceDialogService);
  const isEnabledLoading = useLiveData(
    embeddingService.embedding.isEnabledLoading$
  );

  const handleEmbeddingToggle = useCallback(
    (checked: boolean) => {
      track.$.settingsPanel.indexerEmbedding.toggleWorkspaceEmbedding({
        type: 'Embedding',
        control: 'Workspace embedding',
        option: checked ? 'on' : 'off',
      });

      embeddingService.embedding.setEnabled(checked).catch(error => {
        notify.error({
          title:
            t[
              'com.affine.settings.workspace.indexer-embedding.embedding.switch.error'
            ](),
          message: error.message,
        });
      });
    },
    [embeddingService.embedding, t]
  );

  const handleAttachmentUpload = useCallback(
    (file: File) => {
      track.$.settingsPanel.indexerEmbedding.addAdditionalDocs({
        type: 'Embedding',
        control: 'Select doc',
        docType: file.type,
      });
      embeddingService.embedding.addAttachments([file]);
    },
    [embeddingService.embedding]
  );

  const handleAttachmentsDelete = useCallback(
    (fileId: string) => {
      embeddingService.embedding.removeAttachment(fileId).catch(error => {
        notify.error({
          title:
            t[
              'com.affine.settings.workspace.indexer-embedding.embedding.remove-attachment.error'
            ](),
          message: error.message,
        });

Review comment (suggestion):
```suggestion
        const err = UserFriendlyError.fromAny(error);
        notify.error({
          title:
            t[
              'com.affine.settings.workspace.indexer-embedding.embedding.switch.error'
            ](),
          message: t[`error.${err.name}`](err.data)
        });
```

Code after:

  const isIgnoredDocsLoading = useLiveData(
    embeddingService.embedding.isIgnoredDocsLoading$
  );
  const workspaceDialogService = useService(WorkspaceDialogService);
  const isEnabledLoading = useLiveData(
    embeddingService.embedding.isEnabledLoading$
  );

  const handleEmbeddingToggle = useCallback(
    (checked: boolean) => {
      track.$.settingsPanel.indexerEmbedding.toggleWorkspaceEmbedding({
        type: 'Embedding',
        control: 'Workspace embedding',
        option: checked ? 'on' : 'off',
      });

      embeddingService.embedding.setEnabled(checked).catch(error => {
        const err = UserFriendlyError.fromAny(error);
        notify.error({
          title:
            t[
              'com.affine.settings.workspace.indexer-embedding.embedding.switch.error'
            ](),
          message: t[`error.${err.name}`](err.data),
        });
      });
    },
    [embeddingService.embedding, t]
  );

  const handleAttachmentUpload = useCallback(
    (file: File) => {
      track.$.settingsPanel.indexerEmbedding.addAdditionalDocs({
        type: 'Embedding',
        control: 'Select doc',
        docType: file.type,
      });
      embeddingService.embedding.addAttachments([file]);
    },
    [embeddingService.embedding]
  );

  const handleAttachmentsDelete = useCallback(
    (fileId: string) => {
      embeddingService.embedding.removeAttachment(fileId).catch(error => {
        const err = UserFriendlyError.fromAny(error);
        notify.error({
          title:
            t[
              'com.affine.settings.workspace.indexer-embedding.embedding.remove-attachment.error'