forked from
mary.my.id/atcute
a collection of lightweight TypeScript packages for AT Protocol, the protocol powering Bluesky
1/**
2 * thrown when client authentication method is no longer usable
3 * (e.g., key removed from keyset or server no longer supports method).
4 */
5export class AuthMethodUnsatisfiableError extends Error {
6 override name = 'AuthMethodUnsatisfiableError';
7}
8
9/**
10 * thrown when a session is invalid and cannot be used.
11 */
12export class TokenInvalidError extends Error {
13 override name = 'TokenInvalidError';
14
15 constructor(
16 public readonly sub: string,
17 message = `session for "${sub}" is invalid`,
18 options?: ErrorOptions,
19 ) {
20 super(message, options);
21 }
22}
23
24/**
25 * thrown when token refresh fails.
26 */
27export class TokenRefreshError extends Error {
28 override name = 'TokenRefreshError';
29
30 constructor(
31 public readonly sub: string,
32 message: string,
33 options?: ErrorOptions,
34 ) {
35 super(message, options);
36 }
37}
38
39/**
40 * thrown when a session has been revoked.
41 */
42export class TokenRevokedError extends Error {
43 override name = 'TokenRevokedError';
44
45 constructor(
46 public readonly sub: string,
47 message = `session for "${sub}" was revoked`,
48 options?: ErrorOptions,
49 ) {
50 super(message, options);
51 }
52}
53
54/**
55 * thrown when OAuth response indicates an error.
56 */
57export class OAuthResponseError extends Error {
58 override name = 'OAuthResponseError';
59
60 constructor(
61 public readonly response: Response,
62 public readonly error: string,
63 public readonly errorDescription?: string,
64 ) {
65 super(errorDescription ?? error);
66 }
67
68 get status(): number {
69 return this.response.status;
70 }
71}
72
73/**
74 * thrown when OAuth callback contains an error.
75 */
76export class OAuthCallbackError extends Error {
77 override name = 'OAuthCallbackError';
78
79 constructor(
80 public readonly error: string,
81 public readonly errorDescription?: string,
82 public readonly state?: string,
83 ) {
84 super(errorDescription ?? error);
85 }
86}
87
88/**
89 * thrown when metadata resolution fails.
90 */
91export class OAuthResolverError extends Error {
92 override name = 'OAuthResolverError';
93}