import { SentryApiError } from "@sentry/api"; /** * Error thrown when user input validation fails. * These errors should be returned to the user directly without logging to Sentry. */ export declare class UserInputError extends Error { constructor(message: string, options?: ErrorOptions); } /** * Error thrown when configuration is invalid or missing. * These errors should be returned to the user directly without logging to Sentry. * Typically used for environment configuration issues, connection settings, etc. */ export declare class ConfigurationError extends Error { constructor(message: string, options?: ErrorOptions); } /** * API Error Class Hierarchy * * This module defines a hierarchical error system for the Sentry API client * that automatically categorizes errors based on HTTP status codes. * * Key principles: * - Every class extends `SentryApiError`, the error the generated operations * return, so `instanceof SentryApiError` matches API failures from both the * operations and the request core * - 4xx errors (ApiClientError) are user input errors, not reported to Sentry * - 5xx errors (ApiServerError) are system errors, reported to Sentry * - Specific error types provide additional context and helper methods * - The hierarchy enables type-safe error handling without manual status checks */ /** * Base class for the request core's API errors. * Contains common properties for all API error types. * Status is optional since some errors (like client-side validation) don't have HTTP status codes. * `body` is the parsed response body, the same value as `responseBody`; * `response` is not kept, since the core has consumed it. */ export declare class ApiError extends SentryApiError { readonly detail?: string | undefined; readonly responseBody?: unknown | undefined; constructor(message: string, status?: number, detail?: string | undefined, responseBody?: unknown | undefined); } /** * Client errors (4xx) - User input errors that should NOT be reported to Sentry. * These typically indicate issues with the request that the user can fix. * Also includes client-side validation errors that don't have HTTP status codes. */ export declare class ApiClientError extends ApiError { constructor(message: string, status?: number, detail?: string, responseBody?: unknown); /** * Convert to a user-friendly formatted message. * Returns the standard format: "API error (status): message" or just "API error: message" if no status. * For 404 errors, adds helpful context about checking parameters. */ toUserMessage(): string; /** * Check if this is a permission/authorization error (403) */ isPermissionError(): boolean; /** * Check if this is a not found error (404) */ isNotFoundError(): boolean; /** * Check if this is a validation error (400 or 422) */ isValidationError(): boolean; /** * Check if this is an authentication error (401) */ isAuthenticationError(): boolean; /** * Check if this is a rate limit error (429) */ isRateLimitError(): boolean; } /** * Permission denied error (403). * Includes special handling for multi-project access errors. * `acceptedScopes` comes from the response's `insufficient_scope` challenge, * when it has one: the token lacks every scope the endpoint accepts, and any * one of them is enough. */ export declare class ApiPermissionError extends ApiClientError { readonly acceptedScopes: readonly string[]; constructor(message: string, detail?: string, responseBody?: unknown, acceptedScopes?: readonly string[]); /** * Check if the token lacks the scope the endpoint requires, which retrying * with the same token cannot fix */ isInsufficientScopeError(): boolean; toUserMessage(): string; /** * Check if this is the specific multi-project access error */ isMultiProjectAccessError(): boolean; } /** * Resource not found error (404). * Can include additional context about what resource was not found. */ export declare class ApiNotFoundError extends ApiClientError { readonly resourceType?: string | undefined; readonly resourceId?: string | undefined; constructor(message: string, detail?: string, responseBody?: unknown, resourceType?: string | undefined, resourceId?: string | undefined); } /** * Validation error (400 or 422 for API responses, or no status for client-side validation). * Indicates the request was malformed or contained invalid data. */ export declare class ApiValidationError extends ApiClientError { readonly validationErrors?: Record | undefined; constructor(message: string, status?: 400 | 422, detail?: string, responseBody?: unknown, validationErrors?: Record | undefined); } /** * Authentication error (401). * Indicates the request lacks valid authentication credentials. */ export declare class ApiAuthenticationError extends ApiClientError { constructor(message: string, detail?: string, responseBody?: unknown); } /** * Rate limit error (429). * `retryAfterMs` comes from the response's `Retry-After` or * `X-Sentry-Rate-Limit-Reset` header, when it has one. */ export declare class ApiRateLimitError extends ApiClientError { readonly retryAfterMs?: number | undefined; constructor(message: string, detail?: string, responseBody?: unknown, retryAfterMs?: number | undefined); toUserMessage(): string; } /** * Server errors (5xx) - System errors that SHOULD be reported to Sentry. * These indicate problems with the server that are not the user's fault. */ export declare class ApiServerError extends ApiError { constructor(message: string, status: number, detail?: string, responseBody?: unknown); /** * Check if this is a gateway/proxy error (502, 503, 504) */ isGatewayError(): boolean; /** * Check if this is an internal server error (500) */ isInternalError(): boolean; } /** * Factory function to create the appropriate error type based on HTTP status code. * This centralizes the logic for determining which error class to instantiate. * This is only used for actual API responses, so status is required. */ export declare function createApiError(message: string, status: number, detail?: string, responseBody?: unknown, retryAfterMs?: number, acceptedScopes?: readonly string[]): ApiError; /** * Returns true if `error` is an `ApiAuthenticationError`, either directly or * anywhere within the first few levels of `error.cause`. Tools that wrap * upstream errors as `throw new Error(msg, { cause: apiError })` would * otherwise hide the 401 signal from a direct `instanceof` check. Bounded * depth guards against accidental cycles. */ export declare function isApiAuthenticationErrorDeep(error: unknown): boolean;