Personal Site

improve the error handling bc spotify will die on march 9

custom auth impl already silences errors

vielle.dev 14d66204 f0dc72c5

verified
+63 -48
+61 -47
src/components/home/feeds/Feed.astro
··· 6 6 import Post from "./Post.astro"; 7 7 import type { Author } from "./post-types"; 8 8 import { client } from "./atproto"; 9 + import type { XRPCErrorPayload } from "@atcute/client"; 9 10 10 11 const { ok, data } = await client.get("app.bsky.feed.getAuthorFeed", { 11 12 params: { 12 13 actor: socials.atproto.did, 13 14 limit: 100, 14 - filter: "posts_no_replies" 15 + filter: "posts_no_replies", 15 16 }, 16 17 }); 17 18 18 - if (!ok) { 19 - // error occoured 20 - console.error(data.error, data.message); 21 - 22 - return "Error 500: Internal server error fetching this feed. Try refreshing the page"; 23 - } 24 - 25 - let posts: { 26 - record: AppBskyFeedPost.Main; 27 - author: Author; 28 - uri: ResourceUri; 29 - }[] = data.feed 30 - // make sure it was by me (exclude reposts) 31 - .filter((x) => x.post.author.did === socials.atproto.did) 32 - // makes sure its not a reply 33 - .filter((x) => !x.reply) 34 - // this list now includes original posts & quote skeets 35 - .map((x) => { 36 - return { 37 - record: is(AppBskyFeedPost.mainSchema, x.post.record) 38 - ? x.post.record 39 - : // never type bc it gets filtered out 40 - (undefined as never), 41 - author: { 42 - did: x.post.author.did, 43 - displayName: x.post.author.displayName, 44 - handle: x.post.author.handle, 45 - avatar: x.post.author.avatar, 46 - }, 47 - uri: x.post.uri, 48 - }; 49 - }) 50 - .filter((x) => x.record); 19 + const posts: 20 + | { 21 + record: AppBskyFeedPost.Main; 22 + author: Author; 23 + uri: ResourceUri; 24 + }[] 25 + | undefined = ok 26 + ? data.feed 27 + // make sure it was by me (exclude reposts) 28 + .filter((x) => x.post.author.did === socials.atproto.did) 29 + // makes sure its not a reply 30 + .filter((x) => !x.reply) 31 + // this list now includes original posts & quote skeets 32 + .map((x) => { 33 + return { 34 + record: is(AppBskyFeedPost.mainSchema, x.post.record) 35 + ? x.post.record 36 + : // never type bc it gets filtered out 37 + (undefined as never), 38 + author: { 39 + did: x.post.author.did, 40 + displayName: x.post.author.displayName, 41 + handle: x.post.author.handle, 42 + avatar: x.post.author.avatar, 43 + }, 44 + uri: x.post.uri, 45 + }; 46 + }) 47 + .filter((x) => x.record) 48 + : undefined; 51 49 --- 52 50 53 51 <section class="feed" style={`--box-lr-png: url("${boxLR.src}");`}> ··· 55 53 <h2>Bluesky 🦋</h2> 56 54 <ul> 57 55 { 58 - posts.map((x) => { 59 - const uriFragments = x.uri.match( 60 - new RegExp( 61 - "at:\/\/(?<did>did:(?:plc|web):[^\/]*)\/(?<nsid>[^\/]*)\/(?<rkey>.*)", 62 - ), 63 - ); 64 - let rkey: string = uriFragments?.groups?.rkey ?? ""; 65 - return ( 66 - <li> 67 - <Post post={x.record} author={x.author} {rkey} /> 68 - </li> 69 - ); 70 - }) 56 + posts 57 + ? posts.map((x) => { 58 + const uriFragments = x.uri.match( 59 + new RegExp( 60 + "at:\/\/(?<did>did:(?:plc|web):[^\/]*)\/(?<nsid>[^\/]*)\/(?<rkey>.*)", 61 + ), 62 + ); 63 + let rkey: string = uriFragments?.groups?.rkey ?? ""; 64 + return ( 65 + <li> 66 + <Post post={x.record} author={x.author} {rkey} /> 67 + </li> 68 + ); 69 + }) 70 + : (() => { 71 + console.error( 72 + (data as XRPCErrorPayload).error, 73 + (data as XRPCErrorPayload).message, 74 + ); 75 + return ( 76 + <p> 77 + Internal server error while loading feed: 78 + <br /> 79 + Erorr: <code>{(data as XRPCErrorPayload).error}</code> 80 + <br /> 81 + Message: <code>{(data as XRPCErrorPayload).message}</code> 82 + </p> 83 + ); 84 + })() 71 85 } 72 86 </ul> 73 87 </div>
+2 -1
src/components/home/playing/TopSongs.astro
··· 26 26 .then((tracks) => (!tracks ? throws("Top tracks failed") : tracks)) 27 27 .catch((err) => console.error(err)); 28 28 29 - if (!topSongs) return "Error 500 failed to get top songs!!"; 29 + if (!topSongs) 30 + return "Error: Failed to load top songs. Spotify refresh token may have expired or spotify may be down."; 30 31 --- 31 32 32 33 <ul class="top-songs">