atmosphere explorer
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

error handling fixes

+60 -52
+60 -52
src/App.tsx
··· 56 56 .replace("/post/", "/app.bsky.feed.post/"); 57 57 let did = ""; 58 58 try { 59 - did = uri.split("/")[0]; 60 - if (!uri.startsWith("did:")) { 61 - const res = await rpc.get("com.atproto.identity.resolveHandle", { 62 - params: { handle: uri.split("/")[0] }, 63 - }); 64 - did = res.data.did; 65 - } 59 + rpc = new XRPC({ 60 + handler: new CredentialManager({ 61 + service: "https://public.api.bsky.app", 62 + }), 63 + }); 64 + await resolvePDS(uri.split("/")[0]); 65 + did = 66 + !uri.startsWith("did:") ? 67 + await resolveHandle(uri.split("/")[0]) 68 + : uri.split("/")[0]; 66 69 if (!did) throw Error; 67 - setPDS(await getPDS(did)); 68 - } catch (err) { 70 + } catch { 69 71 setNotice("Could not resolve AT URI"); 72 + return; 70 73 } 71 74 throw redirect( 72 75 `/at/${did}${uri.split("/").length > 1 ? "/" + uri.split("/").slice(1).join("/") : ""}`, 73 76 ); 74 77 }); 78 + 79 + const resolveHandle = async (handle: string) => { 80 + const res = await rpc.get("com.atproto.identity.resolveHandle", { 81 + params: { handle: handle }, 82 + }); 83 + return res.data.did; 84 + }; 75 85 76 86 const resolvePDS = async (repo: string) => { 77 87 try { 78 88 let did = repo; 79 - if (!repo.startsWith("did:")) { 80 - const res = await rpc.get("com.atproto.identity.resolveHandle", { 81 - params: { handle: repo }, 82 - }); 83 - did = res.data.did; 84 - } 89 + if (!repo.startsWith("did:")) did = await resolveHandle(repo); 85 90 if (!did) throw Error; 86 91 const pds = await getPDS(did); 87 92 setPDS(pds.replace("https://", "")); 88 93 return pds; 89 - } catch (err) { 94 + } catch { 90 95 setNotice("Could not resolve PDS"); 91 96 } 92 97 }; ··· 304 309 }; 305 310 306 311 const Home: Component = () => { 312 + setNotice(""); 307 313 return ( 308 314 <div class="flex flex-col break-words font-sans"> 309 315 <div> ··· 434 440 </button> 435 441 </div> 436 442 </form> 437 - <div class="mb-3 mt-4 flex flex-wrap font-mono"> 438 - <Show when={pds() && params.pds}> 439 - <A 440 - end 441 - href={pds()!} 442 - inactiveClass="text-lightblue-500 hover:underline" 443 - > 444 - {pds()} 445 - </A> 446 - </Show> 447 - <Show when={params.repo}> 448 - <span class="mx-1.5">/</span> 449 - <A 450 - end 451 - href={`at/${params.repo}`} 452 - inactiveClass="text-lightblue-500 hover:underline" 453 - > 454 - {params.repo} 455 - </A> 456 - </Show> 457 - <Show when={params.collection}> 458 - <span class="mx-1.5">/</span> 459 - <A 460 - end 461 - href={`at/${params.repo}/${params.collection}`} 462 - inactiveClass="text-lightblue-500 hover:underline" 463 - > 464 - {params.collection} 465 - </A> 466 - </Show> 467 - <Show when={params.rkey}> 468 - <span class="mx-1.5">/</span> 469 - {params.rkey} 470 - </Show> 471 - </div> 472 - <div>{notice()}</div> 443 + <Show when={params.pds}> 444 + <div class="mb-3 mt-4 flex flex-wrap font-mono"> 445 + <Show when={pds() && params.pds}> 446 + <A 447 + end 448 + href={pds()!} 449 + inactiveClass="text-lightblue-500 hover:underline" 450 + > 451 + {pds()} 452 + </A> 453 + </Show> 454 + <Show when={params.repo}> 455 + <span class="mx-1.5">/</span> 456 + <A 457 + end 458 + href={`at/${params.repo}`} 459 + inactiveClass="text-lightblue-500 hover:underline" 460 + > 461 + {params.repo} 462 + </A> 463 + </Show> 464 + <Show when={params.collection}> 465 + <span class="mx-1.5">/</span> 466 + <A 467 + end 468 + href={`at/${params.repo}/${params.collection}`} 469 + inactiveClass="text-lightblue-500 hover:underline" 470 + > 471 + {params.collection} 472 + </A> 473 + </Show> 474 + <Show when={params.rkey}> 475 + <span class="mx-1.5">/</span> 476 + {params.rkey} 477 + </Show> 478 + </div> 479 + </Show> 480 + <div class="my-1">{notice()}</div> 473 481 <div class="flex max-w-full flex-col space-y-1 font-mono"> 474 482 <Show keyed when={useLocation().pathname}> 475 483 {props.children}