kimi-code / packages /oauth /src /errors.ts
SaylorTwift's picture
SaylorTwift HF Staff
Add files using upload-large-folder tool
f0634fb verified
Raw
History Blame Contribute Delete
2.13 kB
/**
* 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';
}
}