Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
if there is a invalid hash return x for cast
Browse files Browse the repository at this point in the history
  • Loading branch information
kevoconnell committed Jul 10, 2024
1 parent 7475244 commit d90f634
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const fetchApiData = async (
let hash = identifier;
let warpcastCastResponseStart = null;
try {
if (
identifier &&
!isValidWarpcastUrl(identifier) &&
!identifier.includes('0x')
) {
throw new Error('Invalid hash');
}
if (identifier && (!isWarpcastURL || identifier.split('/').length >= 5)) {
try {
warpcastCastResponseStart = performance.now();
Expand Down Expand Up @@ -211,7 +218,6 @@ const formatErrorResponse = (
const errorInfo = {
message: error.message,
name: error.name,
stack: error.stack,
response: error.response
? {
status: error.response.status,
Expand All @@ -222,12 +228,12 @@ const formatErrorResponse = (
};
return {
warpcast: {
cast: warpcastCast,
cast: { ...warpcastCast, error: errorInfo },
name: 'Warpcast API',
author: null,
},
neynar: {
cast: neynarCast,
cast: { ...neynarCast, error: errorInfo },
name: 'Neynar API',
author: null,
},
Expand All @@ -253,6 +259,7 @@ export async function fetchCastAndFidData(
fid: number | null
) {
if (!hash && !fid) return { apiData: null, hubData: null };
//if the hash doesnt have 0x return an error
const apiData = await fetchApiData(fid, hash);
if (apiData.error || (!apiData.neynar && !apiData.warpcast))
return { apiData, hubData: null };
Expand Down

0 comments on commit d90f634

Please sign in to comment.