forked from pdsls.dev/pdsls
atproto explorer

fallback when describeRepo fails

juli.ee dfda14be 5051ef47

verified
Changed files
+32 -28
src
views
+32 -28
src/views/repo.tsx
··· 140 } 141 142 rpc = new Client({ handler: new CredentialManager({ service: pds }) }); 143 - const res = await rpc.get("com.atproto.repo.describeRepo", { 144 - params: { repo: did as ActorIdentifier }, 145 - }); 146 - if (res.ok) { 147 - const collections: Record<string, { hidden: boolean; nsids: string[] }> = {}; 148 - res.data.collections.forEach((c) => { 149 - const nsid = c.split("."); 150 - if (nsid.length > 2) { 151 - const authority = `${nsid[0]}.${nsid[1]}`; 152 - collections[authority] = { 153 - nsids: (collections[authority]?.nsids ?? []).concat(nsid.slice(2).join(".")), 154 - hidden: false, 155 - }; 156 - } 157 }); 158 - setNsids(collections); 159 - } else { 160 - console.error(res.data.error); 161 - switch (res.data.error) { 162 - case "RepoDeactivated": 163 - setError("Deactivated"); 164 - break; 165 - case "RepoTakendown": 166 - setError("Takendown"); 167 - break; 168 - default: 169 - setError("Unreachable"); 170 } 171 } 172 - 173 - return res.data; 174 }; 175 176 const [repo] = createResource(fetchRepo);
··· 140 } 141 142 rpc = new Client({ handler: new CredentialManager({ service: pds }) }); 143 + try { 144 + const res = await rpc.get("com.atproto.repo.describeRepo", { 145 + params: { repo: did as ActorIdentifier }, 146 }); 147 + if (res.ok) { 148 + const collections: Record<string, { hidden: boolean; nsids: string[] }> = {}; 149 + res.data.collections.forEach((c) => { 150 + const nsid = c.split("."); 151 + if (nsid.length > 2) { 152 + const authority = `${nsid[0]}.${nsid[1]}`; 153 + collections[authority] = { 154 + nsids: (collections[authority]?.nsids ?? []).concat(nsid.slice(2).join(".")), 155 + hidden: false, 156 + }; 157 + } 158 + }); 159 + setNsids(collections); 160 + } else { 161 + console.error(res.data.error); 162 + switch (res.data.error) { 163 + case "RepoDeactivated": 164 + setError("Deactivated"); 165 + break; 166 + case "RepoTakendown": 167 + setError("Takendown"); 168 + break; 169 + default: 170 + setError("Unreachable"); 171 + } 172 } 173 + 174 + return res.data; 175 + } catch { 176 + return {}; 177 } 178 }; 179 180 const [repo] = createResource(fetchRepo);