UNPKG

@getpaidhq/sdk

Version:

TypeScript SDK for GetPaidHQ API - Comprehensive subscription billing platform

2 lines 1.96 kB
var s=class r extends Error{statusCode;errorCode;details;requestId;constructor(e,t,n,i,o){super(e),this.name="GetPaidHQError",this.statusCode=t,this.errorCode=n,this.details=i,this.requestId=o,Object.setPrototypeOf(this,r.prototype);}},c=class r extends s{constructor(e="Authentication failed",t){super(e,401,"authentication_error",t),this.name="AuthenticationError",Object.setPrototypeOf(this,r.prototype);}},d=class r extends s{constructor(e="Authorization failed",t){super(e,403,"authorization_error",t),this.name="AuthorizationError",Object.setPrototypeOf(this,r.prototype);}},p=class r extends s{constructor(e,t){let n=t?`${e} with id '${t}' not found`:`${e} not found`;super(n,404,"not_found",{resource:e,id:t}),this.name="NotFoundError",Object.setPrototypeOf(this,r.prototype);}},u=class r extends s{constructor(e,t){super(e,400,"validation_error",t),this.name="ValidationError",Object.setPrototypeOf(this,r.prototype);}},h=class r extends s{retryAfter;constructor(e="Rate limit exceeded",t){super(e,429,"rate_limit_error",{retryAfter:t}),this.name="RateLimitError",this.retryAfter=t,Object.setPrototypeOf(this,r.prototype);}},l=class r extends s{constructor(e="Internal server error",t=500){super(e,t,"server_error"),this.name="ServerError",Object.setPrototypeOf(this,r.prototype);}};function g(r){let e=r.response,t=e?.headers["x-request-id"];if(!e)throw new s(r.message||"Network error occurred",void 0,"network_error",void 0,t);let{status:n,data:i}=e,o=i?.error||i?.message||r.message,a=i?.details;switch(n){case 400:throw new u(o,a);case 401:throw new c(o,a);case 403:throw new d(o,a);case 404:throw new p("Resource",void 0);case 429:{let y=e.headers["retry-after"];throw new h(o,y?parseInt(y):void 0)}case 500:case 502:case 503:case 504:throw new l(o,n);default:throw new s(o,n,"api_error",a,t)}}export{s as a,c as b,d as c,p as d,u as e,h as f,l as g,g as h};//# sourceMappingURL=chunk-OSMPDGGU.js.map //# sourceMappingURL=chunk-OSMPDGGU.js.map