File size: 2,127 Bytes
f0634fb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
 * OAuth error classes.
 *
 * All errors derive from {@link OAuthError}. Distinguishing subclasses let
 * callers react appropriately:
 *  - `OAuthUnauthorizedError`: 401/403 from token endpoint → refresh_token
 *    or credentials are bad; drive user through `/login` again.
 *  - `OAuthAccessDeniedError`: user denied the authorization request on the
 *    consent page (`access_denied`); surface as a user-initiated cancel.
 *  - `OAuthConnectionError`: transport-level OAuth request failure; callers
 *    may retry the operation.
 *  - `DeviceCodeExpiredError`: device_code TTL ran out before user approved;
 *    restart the device flow.
 *  - `DeviceCodeTimeoutError`: local 15 min wall-clock budget exhausted
 *    before the user completed approval.
 *  - `RetryableRefreshError`: 429 / 5xx from token endpoint; the refresh
 *    helper retries with exponential backoff before surfacing this.
 */

export class OAuthError extends Error {
  constructor(message: string, options?: ErrorOptions) {
    super(message, options);
    this.name = 'OAuthError';
  }
}

export class OAuthUnauthorizedError extends OAuthError {
  constructor(message: string) {
    super(message);
    this.name = 'OAuthUnauthorizedError';
  }
}

export class OAuthAccessDeniedError extends OAuthError {
  constructor(message = 'Authorization denied.') {
    super(message);
    this.name = 'OAuthAccessDeniedError';
  }
}

export class OAuthConnectionError extends OAuthError {
  constructor(message: string, options?: ErrorOptions) {
    super(message, options);
    this.name = 'OAuthConnectionError';
  }
}

export class DeviceCodeExpiredError extends OAuthError {
  constructor(message = 'Device code expired.') {
    super(message);
    this.name = 'DeviceCodeExpiredError';
  }
}

export class DeviceCodeTimeoutError extends OAuthError {
  constructor(message = 'Device authorization timed out locally.') {
    super(message);
    this.name = 'DeviceCodeTimeoutError';
  }
}

export class RetryableRefreshError extends OAuthError {
  constructor(message: string) {
    super(message);
    this.name = 'RetryableRefreshError';
  }
}