Skip to content

Commit 3ab06ae

Browse files
committed
style(jobs): move swarm error to swarm job file
1 parent 58c4937 commit 3ab06ae

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

apps/jobs/src/errors.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
import type { AxiosError } from "axios";
2-
3-
import { z } from "@blobscan/zod";
4-
51
export class ErrorException extends Error {
62
constructor(message: string, cause?: unknown) {
73
super(message, {
@@ -11,34 +7,3 @@ export class ErrorException extends Error {
117
this.name = this.constructor.name;
128
}
139
}
14-
15-
const swarmApiResponseErrorSchema = z.object({
16-
code: z.number(),
17-
message: z.string(),
18-
reasons: z.array(z.unknown()).optional(),
19-
});
20-
21-
export class SwarmNodeError extends ErrorException {
22-
code: number | undefined;
23-
reasons?: unknown[];
24-
25-
constructor(error: AxiosError) {
26-
let message: string;
27-
let code: number | undefined;
28-
const result = swarmApiResponseErrorSchema.safeParse(error.response?.data);
29-
let reasons: unknown[] | undefined;
30-
31-
if (result.success) {
32-
code = result.data.code;
33-
message = result.data.message;
34-
reasons = result.data.reasons;
35-
} else {
36-
message = error.message;
37-
}
38-
39-
super(message, { cause: error.cause });
40-
41-
this.code = code;
42-
this.reasons = reasons;
43-
}
44-
}

apps/jobs/src/swarm-stamp/SwarmStampCronJob.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,48 @@ import axios from "axios";
44

55
import { formatTtl } from "@blobscan/dates";
66
import { prisma } from "@blobscan/db";
7+
import { z } from "@blobscan/zod";
78

89
import type { CommonCronJobConfig } from "../BaseCronJob";
910
import { BaseCronJob } from "../BaseCronJob";
10-
import { SwarmNodeError } from "../errors";
11+
import { ErrorException } from "../errors";
1112

1213
type BatchData = {
1314
batchID: string;
1415
batchTTL: number;
1516
};
1617

18+
const swarmApiResponseErrorSchema = z.object({
19+
code: z.number(),
20+
message: z.string(),
21+
reasons: z.array(z.unknown()).optional(),
22+
});
23+
24+
export class SwarmNodeError extends ErrorException {
25+
code: number | undefined;
26+
reasons?: unknown[];
27+
28+
constructor(error: AxiosError) {
29+
let message: string;
30+
let code: number | undefined;
31+
const result = swarmApiResponseErrorSchema.safeParse(error.response?.data);
32+
let reasons: unknown[] | undefined;
33+
34+
if (result.success) {
35+
code = result.data.code;
36+
message = result.data.message;
37+
reasons = result.data.reasons;
38+
} else {
39+
message = error.message;
40+
}
41+
42+
super(message, { cause: error.cause });
43+
44+
this.code = code;
45+
this.reasons = reasons;
46+
}
47+
}
48+
1749
export interface SwarmStampCronJobConfig extends CommonCronJobConfig {
1850
beeEndpoint: string;
1951
batchId: string;

0 commit comments

Comments
 (0)