src / models / errors.ts
src / models / errors.ts
/**
* Base exception for all errors in Browse.
* Mapped from Python `exceptions.py` BrowseError.
*/
export class BrowseError extends Error {
constructor(message: string) {
super(message);
this.name = "BrowseError";
}
}
/**
* Exception raised for HTTP networking, connection, or protocol errors.
* Mapped from Python `exceptions.py` HTTPClientError.
*/
export class HTTPClientError extends BrowseError {
public readonly originalError?: Error;
constructor(message: string, originalError?: Error) {
super(message);
this.name = "HTTPClientError";
this.originalError = originalError;
}
}
/**
* Exception raised for provider-specific search or configuration errors.
* Mapped from Python `exceptions.py` ProviderError.
*/
export class ProviderError extends BrowseError {
public readonly originalError?: Error;
constructor(message: string, options?: { originalError?: Error }) {
super(message);
this.name = "ProviderError";
this.originalError = options?.originalError;
}
}
/**
* Exception raised when an API key fails due to authentication or quota exhaustion (401, 403, 429).
* Mapped from Python `exceptions.py` KeyAuthOrQuotaError.
*/
export class KeyAuthOrQuotaError extends ProviderError {
public readonly statusCode: number;
public readonly retryAfter?: number;
constructor(message: string, statusCode: number, retryAfter?: number) {
super(message);
this.name = "KeyAuthOrQuotaError";
this.statusCode = statusCode;
this.retryAfter = retryAfter;
}
public get retryAfterSeconds(): number | undefined {
return this.retryAfter;
}
}
/**
* Exception raised when registering a duplicate or invalid search provider.
* Mapped from Python `exceptions.py` ProviderRegistrationError.
*/
export class ProviderRegistrationError extends ProviderError {
constructor(message: string) {
super(message);
this.name = "ProviderRegistrationError";
}
}
/**
* Exception raised when a search provider has no configured API keys.
* Mapped from Python `exceptions.py` NoAPIKeysError.
*/
export class NoAPIKeysError extends BrowseError {
constructor(message: string) {
super(message);
this.name = "NoAPIKeysError";
}
}
/**
* Exception raised when all available search providers fail during fallback.
* Mapped from Python `exceptions.py` SearchFailedError.
*/
export class SearchFailedError extends BrowseError {
public readonly errors: Record<string, string>;
constructor(message: string, errors: Record<string, string> = {}) {
super(message);
this.name = "SearchFailedError";
this.errors = errors;
}
}
/**
* Base exception for all errors in Browse.
* Mapped from Python `exceptions.py` BrowseError.
*/
export class BrowseError extends Error {
constructor(message: string) {
super(message);
this.name = "BrowseError";
}
}
/**
* Exception raised for HTTP networking, connection, or protocol errors.
* Mapped from Python `exceptions.py` HTTPClientError.
*/
export class HTTPClientError extends BrowseError {
public readonly originalError?: Error;
constructor(message: string, originalError?: Error) {
super(message);
this.name = "HTTPClientError";
this.originalError = originalError;
}
}
/**
* Exception raised for provider-specific search or configuration errors.
* Mapped from Python `exceptions.py` ProviderError.
*/
export class ProviderError extends BrowseError {
public readonly originalError?: Error;
constructor(message: string, options?: { originalError?: Error }) {
super(message);
this.name = "ProviderError";
this.originalError = options?.originalError;
}
}
/**
* Exception raised when an API key fails due to authentication or quota exhaustion (401, 403, 429).
* Mapped from Python `exceptions.py` KeyAuthOrQuotaError.
*/
export class KeyAuthOrQuotaError extends ProviderError {
public readonly statusCode: number;
public readonly retryAfter?: number;
constructor(message: string, statusCode: number, retryAfter?: number) {
super(message);
this.name = "KeyAuthOrQuotaError";
this.statusCode = statusCode;
this.retryAfter = retryAfter;
}
public get retryAfterSeconds(): number | undefined {
return this.retryAfter;
}
}
/**
* Exception raised when registering a duplicate or invalid search provider.
* Mapped from Python `exceptions.py` ProviderRegistrationError.
*/
export class ProviderRegistrationError extends ProviderError {
constructor(message: string) {
super(message);
this.name = "ProviderRegistrationError";
}
}
/**
* Exception raised when a search provider has no configured API keys.
* Mapped from Python `exceptions.py` NoAPIKeysError.
*/
export class NoAPIKeysError extends BrowseError {
constructor(message: string) {
super(message);
this.name = "NoAPIKeysError";
}
}
/**
* Exception raised when all available search providers fail during fallback.
* Mapped from Python `exceptions.py` SearchFailedError.
*/
export class SearchFailedError extends BrowseError {
public readonly errors: Record<string, string>;
constructor(message: string, errors: Record<string, string> = {}) {
super(message);
this.name = "SearchFailedError";
this.errors = errors;
}
}