File tree Expand file tree Collapse file tree 2 files changed +33
-36
lines changed Expand file tree Collapse file tree 2 files changed +33
-36
lines changed Original file line number Diff line number Diff line change 1- import type { AxiosError } from "axios" ;
2-
3- import { z } from "@blobscan/zod" ;
4-
51export 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- }
Original file line number Diff line number Diff line change @@ -4,16 +4,48 @@ import axios from "axios";
44
55import { formatTtl } from "@blobscan/dates" ;
66import { prisma } from "@blobscan/db" ;
7+ import { z } from "@blobscan/zod" ;
78
89import type { CommonCronJobConfig } from "../BaseCronJob" ;
910import { BaseCronJob } from "../BaseCronJob" ;
10- import { SwarmNodeError } from "../errors" ;
11+ import { ErrorException } from "../errors" ;
1112
1213type 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+
1749export interface SwarmStampCronJobConfig extends CommonCronJobConfig {
1850 beeEndpoint : string ;
1951 batchId : string ;
You can’t perform that action at this time.
0 commit comments