File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { json } from "@remix-run/server-runtime" ;
22import { z } from "zod" ;
33import { prisma } from "~/db.server" ;
4+ import { logger } from "~/services/logger.server" ;
45import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server" ;
56import { BulkActionService } from "~/v3/services/bulk/BulkActionV2.server" ;
7+ import { ServiceValidationError } from "~/v3/services/common.server" ;
68
79const ParamsSchema = z . object ( {
810 bulkActionId : z . string ( ) ,
@@ -34,10 +36,12 @@ const { action } = createActionApiRoute(
3436 const result = await service . abort ( params . bulkActionId , authentication . environment . id ) ;
3537 return json ( { id : result . bulkActionId } ) ;
3638 } catch ( error ) {
37- return json (
38- { error : error instanceof Error ? error . message : "Failed to abort bulk action" } ,
39- { status : 400 }
40- ) ;
39+ if ( error instanceof ServiceValidationError ) {
40+ return json ( { error : error . message } , { status : error . status ?? 400 } ) ;
41+ }
42+
43+ logger . error ( "Failed to abort API bulk action" , { error } ) ;
44+ return json ( { error : "Failed to abort bulk action" } , { status : 500 } ) ;
4145 }
4246 }
4347) ;
Original file line number Diff line number Diff line change @@ -57,10 +57,7 @@ const { action } = createActionApiRoute(
5757 }
5858
5959 logger . error ( "Failed to create API bulk action" , { error } ) ;
60- return json (
61- { error : error instanceof Error ? error . message : "Failed to create bulk action" } ,
62- { status : 500 }
63- ) ;
60+ return json ( { error : "Failed to create bulk action" } , { status : 500 } ) ;
6461 }
6562 }
6663) ;
Original file line number Diff line number Diff line change @@ -482,15 +482,15 @@ export class BulkActionService extends BaseService {
482482 } ) ;
483483
484484 if ( ! group ) {
485- throw new Error ( ` Bulk action not found: ${ friendlyId } ` ) ;
485+ throw new ServiceValidationError ( " Bulk action not found" , 404 ) ;
486486 }
487487
488488 if ( group . status === BulkActionStatus . COMPLETED ) {
489- throw new Error ( ` Bulk action group already completed: ${ friendlyId } ` ) ;
489+ throw new ServiceValidationError ( " Bulk action is already completed" , 409 ) ;
490490 }
491491
492492 if ( group . status === BulkActionStatus . ABORTED ) {
493- throw new Error ( ` Bulk action group already aborted: ${ friendlyId } ` ) ;
493+ throw new ServiceValidationError ( " Bulk action is already aborted" , 409 ) ;
494494 }
495495
496496 //ack the job (this doesn't guarantee it won't run again)
You can’t perform that action at this time.
0 commit comments