Skip to content

Commit

Permalink
chore: add error handling for bundler api
Browse files Browse the repository at this point in the history
  • Loading branch information
marthendalnunes committed Dec 3, 2024
1 parent 812a668 commit e6c1180
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions apps/popup/app/api/bundler/[chainId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,32 @@ export async function POST(
request: Request,
{ params: { chainId: chainIdStr } }: { params: { chainId: string } },
) {
const chainId = Number(chainIdStr);
if (!isValidChain(chainId)) {
return new Response('Chain not supported', { status: 404 });
}
try {
const chainId = Number(chainIdStr);
if (!isValidChain(chainId)) {
return new Response('Chain not supported', { status: 404 });
}

const body = await request.json();
const body = await request.json();

const response = await fetch(
`https://api.pimlico.io/v2/${chainId}/rpc?apikey=${env.NEXT_PUBLIC_PIMLICO_API_KEY}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
const response = await fetch(
`https://api.pimlico.io/v2/${chainId}/rpc?apikey=${env.NEXT_PUBLIC_PIMLICO_API_KEY}`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(body),
},
body: JSON.stringify(body),
},
);
);

if (!response.ok) {
return new Response(response.statusText, { status: response.status });
}
if (!response.ok) {
return new Response(response.statusText, { status: response.status });
}

return new Response(JSON.stringify(await response.json()), { status: 200 });
return new Response(JSON.stringify(await response.json()), { status: 200 });
} catch (error) {
console.log('Error processing request', error);
return new Response('Error processing request', { status: 500 });
}
}

0 comments on commit e6c1180

Please sign in to comment.