Skip to content

Commit b212bd7

Browse files
committed
improve errors
1 parent 39b17d9 commit b212bd7

3 files changed

Lines changed: 12 additions & 11 deletions

File tree

apps/webapp/app/routes/api.v1.bulk-actions.$bulkActionId.abort.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { json } from "@remix-run/server-runtime";
22
import { z } from "zod";
33
import { prisma } from "~/db.server";
4+
import { logger } from "~/services/logger.server";
45
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
56
import { BulkActionService } from "~/v3/services/bulk/BulkActionV2.server";
7+
import { ServiceValidationError } from "~/v3/services/common.server";
68

79
const 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
);

apps/webapp/app/routes/api.v1.bulk-actions.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff 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
);

apps/webapp/app/v3/services/bulk/BulkActionV2.server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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)

0 commit comments

Comments
 (0)