From 463573b3fc1e4daf5aad1bd0d986a89f2f1e7878 Mon Sep 17 00:00:00 2001 From: Dong-Ha Kim Date: Fri, 3 Jan 2025 18:33:55 +0100 Subject: [PATCH] fix: gelato status error --- api/relay/_strategies/gelato.ts | 62 ++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/api/relay/_strategies/gelato.ts b/api/relay/_strategies/gelato.ts index bbeca011f..9fbf20ca4 100644 --- a/api/relay/_strategies/gelato.ts +++ b/api/relay/_strategies/gelato.ts @@ -27,9 +27,7 @@ export function getGelatoStrategy(): RelayStrategy { taskStatus.taskState ) ) { - throw new Error( - `Can not relay request via Gelato due to task state ${taskStatus.taskState}` - ); + throw new GelatoTaskStatusError(taskStatus); } if (taskStatus.transactionHash) { @@ -73,20 +71,50 @@ async function relayWithGelatoApi({ return response.data.taskId as string; } +type TaskStatus = { + taskState: + | "CheckPending" + | "ExecPending" + | "ExecSuccess" + | "ExecReverted" + | "WaitingForConfirmation" + | "Blacklisted" + | "Cancelled" + | "NotFound"; + chainId: number; + taskId: string; + creationDate: string; + lastCheckDate?: string; + lastCheckMessage?: string; + transactionHash?: string; + blockNumber?: number; + executionDate?: string; + gasUsed?: string; + effectiveGasPrice?: string; +}; + async function getGelatoTaskStatus(taskId: string) { - const response = await axios.get<{ - task: { - taskState: - | "CheckPending" - | "ExecPending" - | "ExecSuccess" - | "ExecReverted" - | "WaitingForConfirmation" - | "Blacklisted" - | "Cancelled" - | "NotFound"; - transactionHash?: string; - }; - }>(`${gelatoBaseUrl}/tasks/status/${taskId}`); + const response = await axios.get<{ task: TaskStatus }>( + `${gelatoBaseUrl}/tasks/status/${taskId}` + ); return response.data.task; } + +class GelatoTaskStatusError extends Error { + taskStatus: TaskStatus; + + constructor(taskStatus: TaskStatus) { + super( + `Can not relay request via Gelato due to task state ${taskStatus.taskState}` + ); + this.taskStatus = taskStatus; + } + + toJSON() { + return { + name: this.name, + message: this.message, + taskStatus: this.taskStatus, + }; + } +}