Skip to content

Commit

Permalink
chore: better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
albttx committed Dec 13, 2024
1 parent bb92023 commit c18c484
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions functions/balance.mts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CosmosFaucet } from './pkg/faucet';
import { Store } from './pkg/store';

import type { Config, Context } from '@netlify/functions';
import type { Blockchain } from './types/chain';
Expand All @@ -13,8 +12,8 @@ export default async (req: Request, context: Context) => {

const mnemonic = Netlify.env.get('MNEMONIC');
if (!mnemonic) {
return new Response(`env: MNEMONIC is missing`, {
status: 500,
return new Response(JSON.stringify({ error: `env: MNEMONIC is missing` }), {
status: 503,
});
}

Expand All @@ -23,9 +22,12 @@ export default async (req: Request, context: Context) => {
try {
chain = await import(`../chains/${network}/${chain_name}.json`);
} catch (err) {
return new Response(`${network}/${chain_name} not found`, {
status: 400,
});
return new Response(
JSON.stringify({ error: `${network}/${chain_name} not found` }),
{
status: 400,
},
);
}

const faucet = new CosmosFaucet(chain, mnemonic);
Expand All @@ -46,7 +48,7 @@ export default async (req: Request, context: Context) => {
address: acc.address,
});
} catch (err) {
return new Response(`error: ${err}`, {
return new Response(JSON.stringify({ error: err }), {
status: 500,
});
}
Expand Down
3 changes: 2 additions & 1 deletion functions/send.mts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export default async (_req: Request, context: Context) => {
});
} catch (err) {
console.error(err);
return new Response(`failed to send token: ${err}`, {

return new Response(JSON.stringify({ error: err }), {
status: 500,
});
}
Expand Down

0 comments on commit c18c484

Please sign in to comment.