Skip to content

Commit

Permalink
fix: stringify error objects (#703)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcoraven authored Oct 3, 2024
1 parent 2770527 commit 3015e63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/server/routes/contract/write/write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Type, type Static } from "@sinclair/typebox";
import type { FastifyInstance } from "fastify";
import { StatusCodes } from "http-status-codes";
import { prepareContractCall, resolveMethod } from "thirdweb";
import type { AbiFunction } from "thirdweb/utils";
import { stringify, type AbiFunction } from "thirdweb/utils";
import { getContractV5 } from "../../../../utils/cache/getContractv5";
import { queueTransaction } from "../../../../utils/transaction/queueTransation";
import { createCustomError } from "../../../middleware/error";
Expand Down Expand Up @@ -83,7 +83,11 @@ export async function writeToContract(fastify: FastifyInstance) {
try {
method = await resolveMethod(functionName)(contract);
} catch (e: any) {
throw createCustomError(`${e}`, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
throw createCustomError(
stringify(e),
StatusCodes.BAD_REQUEST,
"BAD_REQUEST",
);
}
const transaction = prepareContractCall({
contract,
Expand Down
7 changes: 6 additions & 1 deletion src/utils/transaction/queueTransation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type Hex,
type PreparedTransaction,
} from "thirdweb";
import { stringify } from "thirdweb/utils";
import { createCustomError } from "../../server/middleware/error";
import type { txOverridesWithValueSchema } from "../../server/schemas/txOverrides";
import { parseTransactionOverrides } from "../../server/utils/transactionOverrides";
Expand Down Expand Up @@ -41,7 +42,11 @@ export async function queueTransaction(args: QueuedTransactionParams) {
try {
data = await encode(transaction);
} catch (e) {
throw createCustomError(`${e}`, StatusCodes.BAD_REQUEST, "BAD_REQUEST");
throw createCustomError(
stringify(e),
StatusCodes.BAD_REQUEST,
"BAD_REQUEST",
);
}

const insertedTransaction: InsertedTransaction = {
Expand Down
4 changes: 2 additions & 2 deletions src/worker/tasks/sendTransactionWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const _sendUserOp = async (
const erroredTransaction: ErroredTransaction = {
...queuedTransaction,
status: "errored",
errorMessage: `${e}`,
errorMessage: stringify(e),
};
job.log(
`Failed to populate transaction: ${erroredTransaction.errorMessage}`,
Expand Down Expand Up @@ -231,7 +231,7 @@ const _sendTransaction = async (
const erroredTransaction: ErroredTransaction = {
...queuedTransaction,
status: "errored",
errorMessage: `${e}`,
errorMessage: stringify(e),
};
job.log(
`Failed to populate transaction: ${erroredTransaction.errorMessage}`,
Expand Down

0 comments on commit 3015e63

Please sign in to comment.