Comparing version 1.0.0 to 1.0.1
@@ -276,2 +276,3 @@ declare enum PayvraInvoiceStatus { | ||
constructor(config: PayvraConfig); | ||
private handleError; | ||
fetchCurrencies(): Promise<FetchCurrenciesResponse>; | ||
@@ -278,0 +279,0 @@ createInvoice(params: CreateInvoiceParams): Promise<CreateInvoiceResponse>; |
@@ -44,2 +44,10 @@ "use strict"; | ||
var import_axios = __toESM(require("axios")); | ||
var PayvraApiError = class extends Error { | ||
constructor(message, statusCode, response) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
this.response = response; | ||
this.name = "PayvraApiError"; | ||
} | ||
}; | ||
var PayvraClient = class { | ||
@@ -54,2 +62,15 @@ constructor(config) { | ||
} | ||
handleError(error, operation) { | ||
var _a, _b, _c, _d; | ||
if (import_axios.default.isAxiosError(error)) { | ||
throw new PayvraApiError( | ||
`${operation} failed: ${((_b = (_a = error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || error.message}`, | ||
(_c = error.response) == null ? void 0 : _c.status, | ||
(_d = error.response) == null ? void 0 : _d.data | ||
); | ||
} | ||
throw new PayvraApiError( | ||
`${operation} failed: ${error instanceof Error ? error.message : "Unknown error"}` | ||
); | ||
} | ||
async fetchCurrencies() { | ||
@@ -59,12 +80,11 @@ try { | ||
`${this.baseUrl}/currencies`, | ||
{ | ||
headers: this.headers | ||
} | ||
{}, | ||
{ headers: this.headers } | ||
); | ||
if (!response.data) { | ||
throw new Error("Failed to fetch currencies"); | ||
throw new PayvraApiError("No data received when fetching currencies"); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error creating invoice: ${error}`); | ||
throw this.handleError(error, "Fetch currencies"); | ||
} | ||
@@ -77,12 +97,10 @@ } | ||
params, | ||
{ | ||
headers: this.headers | ||
} | ||
{ headers: this.headers } | ||
); | ||
if (!response.data) { | ||
throw new Error("Failed to create invoice"); | ||
throw new PayvraApiError("No data received when creating invoice"); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error creating invoice: ${error}`); | ||
throw this.handleError(error, "Create invoice"); | ||
} | ||
@@ -100,7 +118,7 @@ } | ||
if (!response.data) { | ||
throw new Error("Failed to fetch invoice"); | ||
throw new PayvraApiError("No data received when fetching invoice"); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error fetching invoice: ${error}`); | ||
throw this.handleError(error, "Fetch invoice"); | ||
} | ||
@@ -116,7 +134,9 @@ } | ||
if (!response.data) { | ||
throw new Error("Failed to create whitelabel invoice"); | ||
throw new PayvraApiError( | ||
"No data received when creating whitelabel invoice" | ||
); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error creating whitelabel invoice: ${error}`); | ||
throw this.handleError(error, "Create whitelabel invoice"); | ||
} | ||
@@ -132,7 +152,7 @@ } | ||
if (!response.data) { | ||
throw new Error("Failed to create payout"); | ||
throw new PayvraApiError("No data received when creating payout"); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error creating payout: ${error}`); | ||
throw this.handleError(error, "Create payout"); | ||
} | ||
@@ -150,7 +170,7 @@ } | ||
if (!response.data) { | ||
throw new Error("Failed to fetch payout"); | ||
throw new PayvraApiError("No data received when fetching payout"); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error fetching payout: ${error}`); | ||
throw this.handleError(error, "Fetch payout"); | ||
} | ||
@@ -167,7 +187,9 @@ } | ||
if (!response.data) { | ||
throw new Error("Failed to fetch exchange pairs"); | ||
throw new PayvraApiError( | ||
"No data received when fetching exchange pairs" | ||
); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error fetching exchange pairs: ${error}`); | ||
throw this.handleError(error, "Fetch exchange pairs"); | ||
} | ||
@@ -185,7 +207,7 @@ } | ||
if (!response.data) { | ||
throw new Error("Failed to create exchange"); | ||
throw new PayvraApiError("No data received when creating exchange"); | ||
} | ||
return response.data; | ||
} catch (error) { | ||
throw new Error(`Error creating exchange: ${error}`); | ||
throw this.handleError(error, "Create exchange"); | ||
} | ||
@@ -192,0 +214,0 @@ } |
{ | ||
"name": "payvra-sdk", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Official TypeScript SDK for the Payvra API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31346
736