A decentralized music tracking and discovery platform built on AT Protocol 🎵
0
fork

Configure Feed

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

Make agent optional and guard its usage

+18 -10
+18 -10
apps/api/src/xrpc/app/rocksky/actor/getProfile.ts
··· 124 124 }: WithServiceEndpoint): Effect.Effect<WithAgent, Error> => 125 125 Effect.tryPromise({ 126 126 try: async () => { 127 + let agent: Agent | AtpAgent | undefined; 128 + try { 129 + agent = serviceEndpoint 130 + ? new AtpAgent({ service: serviceEndpoint }) 131 + : await createAgent(ctx.oauthClient, did); 132 + } catch (error) { 133 + consola.error("Failed to create agent:", error); 134 + } 127 135 return { 128 136 ctx, 129 137 did, 130 138 params, 131 - agent: serviceEndpoint 132 - ? new AtpAgent({ service: serviceEndpoint }) 133 - : await createAgent(ctx.oauthClient, did), 139 + agent, 134 140 }; 135 141 }, 136 142 catch: (error) => new Error(`Failed to create agent: ${error}`), ··· 182 188 try: async () => { 183 189 let record = {}; 184 190 try { 185 - const { data } = await agent.com.atproto.repo.getRecord({ 186 - repo: did, 187 - collection: "app.bsky.actor.profile", 188 - rkey: "self", 189 - }); 190 - record = data; 191 + if (agent) { 192 + const { data } = await agent.com.atproto.repo.getRecord({ 193 + repo: did, 194 + collection: "app.bsky.actor.profile", 195 + rkey: "self", 196 + }); 197 + record = data; 198 + } 191 199 } catch (error) { 192 200 consola.error("Failed to retrieve profile record:", error); 193 201 } ··· 416 424 ctx: Context; 417 425 did?: string; 418 426 params: QueryParams; 419 - agent: Agent | AtpAgent; 427 + agent?: Agent | AtpAgent; 420 428 }; 421 429 422 430 type WithUser = {