@routstr/sdk 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2046,22 +2046,31 @@ var RoutstrClient = class {
2046
2046
  try {
2047
2047
  const url = `${baseUrl.replace(/\/$/, "")}${path}`;
2048
2048
  if (this.mode === "xcashu") this._log("DEBUG", "HEADERS,", headers);
2049
+ this._log("DEBUG", "HEADERS,", headers);
2049
2050
  const response = await fetch(url, {
2050
2051
  method,
2051
2052
  headers,
2052
2053
  body: body === void 0 || method === "GET" ? void 0 : JSON.stringify(body)
2053
2054
  });
2054
2055
  if (this.mode === "xcashu") this._log("DEBUG", "response,", response);
2056
+ this._log("DEBUG", "response,", response);
2055
2057
  response.baseUrl = baseUrl;
2056
2058
  response.token = token;
2057
2059
  if (!response.ok) {
2058
2060
  const requestId = response.headers.get("x-routstr-request-id") || void 0;
2061
+ let bodyText;
2062
+ try {
2063
+ bodyText = await response.text();
2064
+ } catch (e) {
2065
+ bodyText = void 0;
2066
+ }
2059
2067
  return await this._handleErrorResponse(
2060
2068
  params,
2061
2069
  token,
2062
2070
  response.status,
2063
2071
  requestId,
2064
- this.mode === "xcashu" ? response.headers.get("x-cashu") ?? void 0 : void 0
2072
+ this.mode === "xcashu" ? response.headers.get("x-cashu") ?? void 0 : void 0,
2073
+ bodyText
2065
2074
  );
2066
2075
  }
2067
2076
  return response;
@@ -2080,7 +2089,7 @@ var RoutstrClient = class {
2080
2089
  /**
2081
2090
  * Handle error responses with failover
2082
2091
  */
2083
- async _handleErrorResponse(params, token, status, requestId, xCashuRefundToken) {
2092
+ async _handleErrorResponse(params, token, status, requestId, xCashuRefundToken, responseBody) {
2084
2093
  const { path, method, body, selectedModel, baseUrl, mintUrl } = params;
2085
2094
  let tryNextProvider = false;
2086
2095
  this._log(
@@ -2150,7 +2159,8 @@ var RoutstrClient = class {
2150
2159
  );
2151
2160
  }
2152
2161
  }
2153
- if (status === 402 && !tryNextProvider && (this.mode === "apikeys" || this.mode === "lazyrefund")) {
2162
+ if ((status === 402 || status === 413 && responseBody?.includes("Insufficient balance")) && !tryNextProvider && (this.mode === "apikeys" || this.mode === "lazyrefund")) {
2163
+ console.log("RESPONSFE ", responseBody);
2154
2164
  const topupResult = await this.balanceManager.topUp({
2155
2165
  mintUrl,
2156
2166
  baseUrl,