personal web client for Bluesky
typescript
solidjs
bluesky
atcute
1import { ClientResponseError } from '@atcute/client';
2import { TokenRefreshError } from '@atcute/oauth-browser-client';
3
4export const formatXRPCError = (err: ClientResponseError): string => {
5 const name = err.error;
6 return (name ? name + ': ' : '') + err.description;
7};
8
9export const formatQueryError = (err: unknown) => {
10 if (err instanceof TokenRefreshError) {
11 return `Account session is no longer valid`;
12 }
13
14 if (err instanceof ClientResponseError) {
15 const kind = err.error;
16
17 if (kind === 'invalid_token') {
18 return `Account session is no longer valid`;
19 }
20
21 if (kind === 'UpstreamFailure') {
22 return `Server appears to be experiencing issues, try again later`;
23 }
24
25 if (kind === 'InternalServerError') {
26 return `Server is having issues processing this request, try again later`;
27 }
28
29 return formatXRPCError(err);
30 }
31
32 if (err instanceof Error) {
33 if (/NetworkError|Failed to fetch|timed out|abort/.test(err.message)) {
34 return `Unable to access the internet, try again later`;
35 }
36 }
37
38 return '' + err;
39};