Просмотр исходного кода

refactor(app): share bulk-export duplicate-job error code constant

Extract the 'page_export.duplicate_bulk_export_job_error' string into a
shared PAGE_BULK_EXPORT_DUPLICATE_JOB_ERROR_CODE constant in the feature's
interfaces module, and reference it from both the API route and the client
modal to avoid duplicating the literal across server and client.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
tomoyuki-t 1 день назад
Родитель
Сommit
18908fb4b6

+ 5 - 2
apps/app/src/features/page-bulk-export/client/components/PageBulkExportSelectModal.tsx

@@ -9,7 +9,10 @@ import { toastError, toastSuccess } from '~/client/util/toastr';
 import { useCurrentPagePath } from '~/states/page';
 import { isPdfBulkExportEnabledAtom } from '~/states/server-configurations';
 
-import { PageBulkExportFormat } from '../../interfaces/page-bulk-export';
+import {
+  PAGE_BULK_EXPORT_DUPLICATE_JOB_ERROR_CODE,
+  PageBulkExportFormat,
+} from '../../interfaces/page-bulk-export';
 import {
   usePageBulkExportSelectModalActions,
   usePageBulkExportSelectModalStatus,
@@ -38,7 +41,7 @@ const PageBulkExportSelectModalSubstance = (): JSX.Element => {
         close();
       } catch (e) {
         const errorCode = e?.[0].code ?? 'page_export.failed_to_export';
-        if (errorCode === 'page_export.duplicate_bulk_export_job_error') {
+        if (errorCode === PAGE_BULK_EXPORT_DUPLICATE_JOB_ERROR_CODE) {
           // Keep the substance mounted so the restart modal can render.
           // Closing here would unmount the substance and discard isRestartModalOpened.
           setDuplicateJobInfo(e[0].args.duplicateJob);

+ 5 - 0
apps/app/src/features/page-bulk-export/interfaces/page-bulk-export.ts

@@ -15,6 +15,11 @@ export const PageBulkExportFormat = {
 export type PageBulkExportFormat =
   (typeof PageBulkExportFormat)[keyof typeof PageBulkExportFormat];
 
+// Error code shared between the API route and the client to detect a
+// duplicate bulk export job in progress. Keep this as the single source of truth.
+export const PAGE_BULK_EXPORT_DUPLICATE_JOB_ERROR_CODE =
+  'page_export.duplicate_bulk_export_job_error';
+
 export const PageBulkExportJobInProgressStatus = {
   initializing: 'initializing', // preparing for export
   exporting: 'exporting', // exporting to fs

+ 2 - 1
apps/app/src/features/page-bulk-export/server/routes/apiv3/page-bulk-export.ts

@@ -9,6 +9,7 @@ import loginRequiredFactory from '~/server/middlewares/login-required';
 import type { ApiV3Response } from '~/server/routes/apiv3/interfaces/apiv3-response';
 import loggerFactory from '~/utils/logger';
 
+import { PAGE_BULK_EXPORT_DUPLICATE_JOB_ERROR_CODE } from '../../../interfaces/page-bulk-export';
 import {
   DuplicateBulkExportJobError,
   pageBulkExportService,
@@ -61,7 +62,7 @@ module.exports = (crowi: Crowi): Router => {
           return res.apiv3Err(
             new ErrorV3(
               'Duplicate bulk export job is in progress',
-              'page_export.duplicate_bulk_export_job_error',
+              PAGE_BULK_EXPORT_DUPLICATE_JOB_ERROR_CODE,
               undefined,
               { duplicateJob: { createdAt: err.duplicateJob.createdAt } },
             ),