{"version":3,"sources":["../src/errors/errors.ts"],"names":["GetPaidHQError","_GetPaidHQError","message","statusCode","errorCode","details","requestId","AuthenticationError","_AuthenticationError","AuthorizationError","_AuthorizationError","NotFoundError","_NotFoundError","resource","id","ValidationError","_ValidationError","RateLimitError","_RateLimitError","retryAfter","ServerError","_ServerError","handleApiError","error","response","status","data"],"mappings":"aAGO,IAAMA,EAAN,MAAMC,CAAAA,SAAuB,KAAM,CACxB,UAAA,CACA,UACA,OAAA,CACA,SAAA,CAEhB,WAAA,CACEC,CAAAA,CACAC,EACAC,CAAAA,CACAC,CAAAA,CACAC,EACA,CACA,KAAA,CAAMJ,CAAO,CAAA,CACb,IAAA,CAAK,IAAA,CAAO,gBAAA,CACZ,KAAK,UAAA,CAAaC,CAAAA,CAClB,KAAK,SAAA,CAAYC,CAAAA,CACjB,KAAK,OAAA,CAAUC,CAAAA,CACf,IAAA,CAAK,SAAA,CAAYC,EACjB,MAAA,CAAO,cAAA,CAAe,KAAML,CAAAA,CAAe,SAAS,EACtD,CACF,CAAA,CAEaM,CAAAA,CAAN,MAAMC,UAA4BR,CAAe,CACtD,YAAYE,CAAAA,CAAU,uBAAA,CAAyBG,EAA+B,CAC5E,KAAA,CAAMH,CAAAA,CAAS,GAAA,CAAK,uBAAwBG,CAAO,CAAA,CACnD,KAAK,IAAA,CAAO,qBAAA,CACZ,OAAO,cAAA,CAAe,IAAA,CAAMG,CAAAA,CAAoB,SAAS,EAC3D,CACF,CAAA,CAEaC,EAAN,MAAMC,CAAAA,SAA2BV,CAAe,CACrD,WAAA,CAAYE,CAAAA,CAAU,sBAAA,CAAwBG,EAA+B,CAC3E,KAAA,CAAMH,EAAS,GAAA,CAAK,qBAAA,CAAuBG,CAAO,CAAA,CAClD,IAAA,CAAK,IAAA,CAAO,oBAAA,CACZ,OAAO,cAAA,CAAe,IAAA,CAAMK,EAAmB,SAAS,EAC1D,CACF,CAAA,CAEaC,CAAAA,CAAN,MAAMC,CAAAA,SAAsBZ,CAAe,C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\nimport { ErrorResponse } from '../types';\n\nexport class GetPaidHQError extends Error {\n  public readonly statusCode?: number;\n  public readonly errorCode?: string;\n  public readonly details?: Record<string, any>;\n  public readonly requestId?: string;\n\n  constructor(\n    message: string,\n    statusCode?: number,\n    errorCode?: string,\n    details?: Record<string, any>,\n    requestId?: string,\n  ) {\n    super(message);\n    this.name = 'GetPaidHQError';\n    this.statusCode = statusCode;\n    this.errorCode = errorCode;\n    this.details = details;\n    this.requestId = requestId;\n    Object.setPrototypeOf(this, GetPaidHQError.prototype);\n  }\n}\n\nexport class AuthenticationError extends GetPaidHQError {\n  constructor(message = 'Authentication failed', details?: Record<string, any>) {\n    super(message, 401, 'authentication_error', details);\n    this.name = 'AuthenticationError';\n    Object.setPrototypeOf(this, AuthenticationError.prototype);\n  }\n}\n\nexport class AuthorizationError extends GetPaidHQError {\n  constructor(message = 'Authorization failed', details?: Record<string, any>) {\n    super(message, 403, 'authorization_error', details);\n    this.name = 'AuthorizationError';\n    Object.setPrototypeOf(this, AuthorizationError.prototype);\n  }\n}\n\nexport class NotFoundError extends GetPaidHQError {\n  constructor(resource: string, id?: string) {\n    const message = id ? `${resource} with id '${id}' not found` : `${resource} not found`;\n    super(message, 404, 'not_found', { resource, id });\n    this.name = 'NotFoundError';\n    Object.setPrototypeOf(this, NotFoundError.prototype);\n  }\n}\n\nexport class ValidationError extends GetPaidHQError {\n  constructor(message: string, details?: Record<string, any>) {\n    super(message, 400, 'validation_error', details);\n    this.name = 'ValidationError';\n    Object.setPrototypeOf(this, ValidationError.prototype);\n  }\n}\n\nexport class RateLimitError extends GetPaidHQError {\n  public readonly retryAfter?: number;\n\n  constructor(message = 'Rate limit exceeded', retryAfter?: number) {\n    super(message, 429, 'rate_limit_error', { retryAfter });\n    this.name = 'RateLimitError';\n    this.retryAfter = retryAfter;\n    Object.setPrototypeOf(this, RateLimitError.prototype);\n  }\n}\n\nexport class ServerError extends GetPaidHQError {\n  constructor(message = 'Internal server error', statusCode = 500) {\n    super(message, statusCode, 'server_error');\n    this.name = 'ServerError';\n    Object.setPrototypeOf(this, ServerError.prototype);\n  }\n}\n\nexport function handleApiError(error: AxiosError<ErrorResponse>): never {\n  const response = error.response;\n  const requestId = response?.headers['x-request-id'] as string | undefined;\n\n  if (!response) {\n    throw new GetPaidHQError(\n      error.message || 'Network error occurred',\n      undefined,\n      'network_error',\n      undefined,\n      requestId,\n    );\n  }\n\n  const { status, data } = response;\n  const message = data?.error || data?.message || error.message;\n  const details = data?.details;\n\n  switch (status) {\n    case 400:\n      throw new ValidationError(message, details);\n    case 401:\n      throw new AuthenticationError(message, details);\n    case 403:\n      throw new AuthorizationError(message, details);\n    case 404:\n      throw new NotFoundError('Resource', undefined);\n    case 429: {\n      const retryAfter = response.headers['retry-after'];\n      throw new RateLimitError(message, retryAfter ? parseInt(retryAfter as string) : undefined);\n    }\n    case 500:\n    case 502:\n    case 503:\n    case 504:\n      throw new ServerError(message, status);\n    default:\n      throw new GetPaidHQError(message, status, 'api_error', details, requestId);\n  }\n}\n"]}