a tool for shared writing and social publishing

catch constellation errors

+23 -19
+23 -19
app/lish/[did]/[publication]/[rkey]/getPostPageData.ts
··· 60 60 export async function getConstellationBacklinks( 61 61 url: string, 62 62 ): Promise<{ uri: string }[]> { 63 - let baseURL = `https://constellation.microcosm.blue/xrpc/blue.microcosm.links.getBacklinks?subject=${encodeURIComponent(url)}`; 64 - let externalEmbeds = new URL( 65 - `${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:embed.external.uri")}`, 66 - ); 67 - let linkFacets = new URL( 68 - `${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:facets[].features[app.bsky.richtext.facet#link].uri")}`, 69 - ); 63 + try { 64 + let baseURL = `https://constellation.microcosm.blue/xrpc/blue.microcosm.links.getBacklinks?subject=${encodeURIComponent(url)}`; 65 + let externalEmbeds = new URL( 66 + `${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:embed.external.uri")}`, 67 + ); 68 + let linkFacets = new URL( 69 + `${baseURL}&source=${encodeURIComponent("app.bsky.feed.post:facets[].features[app.bsky.richtext.facet#link].uri")}`, 70 + ); 70 71 71 - let [links, embeds] = (await Promise.all([ 72 - fetch(linkFacets, { headers, next: { revalidate: 3600 } }).then((req) => 73 - req.json(), 74 - ), 75 - fetch(externalEmbeds, { headers, next: { revalidate: 3600 } }).then((req) => 76 - req.json(), 77 - ), 78 - ])) as ConstellationResponse[]; 72 + let [links, embeds] = (await Promise.all([ 73 + fetch(linkFacets, { headers, next: { revalidate: 3600 } }).then((req) => 74 + req.json(), 75 + ), 76 + fetch(externalEmbeds, { headers, next: { revalidate: 3600 } }).then( 77 + (req) => req.json(), 78 + ), 79 + ])) as ConstellationResponse[]; 79 80 80 - let uris = [...links.records, ...embeds.records].map((i) => 81 - AtUri.make(i.did, i.collection, i.rkey).toString(), 82 - ); 81 + let uris = [...links.records, ...embeds.records].map((i) => 82 + AtUri.make(i.did, i.collection, i.rkey).toString(), 83 + ); 83 84 84 - return uris.map((uri) => ({ uri })); 85 + return uris.map((uri) => ({ uri })); 86 + } catch (e) { 87 + return []; 88 + } 85 89 } 86 90 87 91 type ConstellationResponse = {