feat: better error handler

This commit is contained in:
reya 2024-01-16 19:56:07 +07:00
parent 1503d90bd5
commit 33dd8b1d8a
3 changed files with 28 additions and 25 deletions

View File

@ -140,11 +140,10 @@ export class Ark {
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST, cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST,
}); });
if (!profile) return null; if (!profile) throw new Error("user not found");
return profile; return profile;
} catch (e) { } catch {
console.log(pubkey); throw new Error("user not found");
console.error(e);
} }
} }
@ -226,29 +225,34 @@ export class Ark {
} }
public async getEventById(id: string) { public async getEventById(id: string) {
let eventId: string = id.replace("nostr:", "").split("'")[0].split(".")[0]; try {
let eventId: string = id
.replace("nostr:", "")
.split("'")[0]
.split(".")[0];
if ( if (
eventId.startsWith("nevent1") || eventId.startsWith("nevent1") ||
eventId.startsWith("note1") || eventId.startsWith("note1") ||
eventId.startsWith("naddr1") eventId.startsWith("naddr1")
) { ) {
const decode = nip19.decode(eventId); const decode = nip19.decode(eventId);
if (decode.type === "nevent") eventId = decode.data.id; if (decode.type === "nevent") eventId = decode.data.id;
if (decode.type === "note") eventId = decode.data; if (decode.type === "note") eventId = decode.data;
if (decode.type === "naddr") { if (decode.type === "naddr") {
return await this.ndk.fetchEvent({ return await this.ndk.fetchEvent({
kinds: [decode.data.kind], kinds: [decode.data.kind],
"#d": [decode.data.identifier], "#d": [decode.data.identifier],
authors: [decode.data.pubkey], authors: [decode.data.pubkey],
}); });
}
} }
}
return await this.ndk.fetchEvent(id, { return await this.ndk.fetchEvent(id);
cacheUsage: NDKSubscriptionCacheUsage.CACHE_FIRST, } catch {
}); throw new Error("event not found");
}
} }
public async getEventByFilter({ filter }: { filter: NDKFilter }) { public async getEventByFilter({ filter }: { filter: NDKFilter }) {

View File

@ -26,7 +26,6 @@ export const MentionNote = memo(function MentionNote({
} }
if (isError || !data) { if (isError || !data) {
console.log(eventId);
return ( return (
<div <div
contentEditable={false} contentEditable={false}

View File

@ -22,7 +22,7 @@ export const MentionUser = memo(function MentionUser({
? "@anon" ? "@anon"
: isError : isError
? pubkey ? pubkey
: `@${user.name || user.displayName || user.username || "anon"}`} : `@${user?.name || user?.displayName || user?.username || "anon"}`}
</DropdownMenu.Trigger> </DropdownMenu.Trigger>
<DropdownMenu.Content className="left-[50px] z-50 relative flex w-[200px] flex-col overflow-hidden rounded-xl border border-neutral-200 bg-neutral-950 focus:outline-none dark:border-neutral-900"> <DropdownMenu.Content className="left-[50px] z-50 relative flex w-[200px] flex-col overflow-hidden rounded-xl border border-neutral-200 bg-neutral-950 focus:outline-none dark:border-neutral-900">
<DropdownMenu.Item asChild> <DropdownMenu.Item asChild>