Skip to content

Commit

Permalink
Return 404 instead of 500 when no contract is set
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Feb 21, 2025
1 parent f75f7b6 commit 0d81ff4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/routes/[network]/(explorer)/contract/[contract]/+layout.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import * as m from '$lib/paraglide/messages.js';
import { Name, type ABI } from '@wharfkit/antelope';
import { error } from '@sveltejs/kit';

import * as m from '$lib/paraglide/messages.js';
import type { LayoutLoad } from './$types';

export const load: LayoutLoad = async ({ fetch, params, parent }) => {
const { network } = await parent();
const response = await fetch(`/${params.network}/api/contract/${params.contract}`);
const json = await response.json();

if (!response.ok || !json.abi.abi) {
return error(404, {
message: `No contract is currently deployed to the ${params.contract} account.`,
code: 'NOT_FOUND'
});
}
const abi: ABI = json.abi.abi;

return {
Expand Down

0 comments on commit 0d81ff4

Please sign in to comment.