Skip to content

Commit 68b3ed1

Browse files
authored
fix: return 400 error on invalid args passed to read endpoint (#767)
1 parent a121730 commit 68b3ed1

File tree

1 file changed

+7
-12
lines changed
  • src/server/routes/contract/read

1 file changed

+7
-12
lines changed

src/server/routes/contract/read/read.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Type } from "@sinclair/typebox";
22
import type { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { getContract } from "../../../../utils/cache/getContract";
5+
import { prettifyError } from "../../../../utils/error";
56
import { createCustomError } from "../../../middleware/error";
67
import {
78
readRequestQuerySchema,
@@ -64,22 +65,16 @@ export async function readContract(fastify: FastifyInstance) {
6465
});
6566

6667
let returnData: unknown;
67-
6868
try {
6969
returnData = await contract.call(functionName, parsedArgs ?? []);
7070
} catch (e) {
71-
if (
72-
e instanceof Error &&
73-
(e.message.includes("is not a function") ||
74-
e.message.includes("arguments, but"))
75-
) {
76-
throw createCustomError(
77-
e.message,
78-
StatusCodes.BAD_REQUEST,
79-
"BAD_REQUEST",
80-
);
81-
}
71+
throw createCustomError(
72+
prettifyError(e),
73+
StatusCodes.BAD_REQUEST,
74+
"BAD_REQUEST",
75+
);
8276
}
77+
8378
returnData = bigNumberReplacer(returnData);
8479

8580
reply.status(StatusCodes.OK).send({

0 commit comments

Comments
 (0)