Skip to content

Commit

Permalink
Adding 404 to token page/api
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Feb 21, 2025
1 parent fba42fa commit a8cb2a6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { API, Asset, Name, Struct, type AssetType, type NameType } from '@wharfkit/antelope';
import { error } from '@sveltejs/kit';

import type { PageLoad } from './$types';

interface LightAPIHolder {
Expand All @@ -18,6 +20,9 @@ export const load: PageLoad = async ({ fetch, params, parent, url }) => {
const count = Number(url.searchParams.get('count')) || 100;
const baseUrl = `/${network}/api/token/${params.contract}/${params.symbol}?count=${count}`;
const response = await fetch(baseUrl);
if (!response.ok) {
return error(404, 'Token not found');
}
const json = await response.json();

const stats = API.v1.GetCurrencyStatsItemResponse.from(json.stats);
Expand Down
4 changes: 4 additions & 0 deletions src/routes/[network]/api/token/[contract]/[symbol]/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export async function GET({ locals: { network }, params, url }: RequestEvent) {
const symbol = params.symbol?.toLocaleUpperCase();
const count = Number(url.searchParams.get('count')) || 100;
const stats = await network.client.v1.chain.get_currency_stats(contract, symbol);
if (stats[symbol] === undefined) {
console.log('abort');
return json({ error: 'Token not found' }, { status: 404 });
}
const topholders = await getTopHolders(network, contract, symbol, count);
const numholders = await getNumHolders(network, contract, symbol);

Expand Down

0 comments on commit a8cb2a6

Please sign in to comment.