bunnyquery 1.3.2 → 1.3.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.
package/bunnyquery.js CHANGED
@@ -196,6 +196,36 @@ ${options.inlineContentPlaceholder}
196
196
  }
197
197
  return false;
198
198
  }
199
+ function isNonRetryableRequestError(input) {
200
+ if (!input || typeof input !== "object") return false;
201
+ var status = typeof input.status_code === "number" ? input.status_code : typeof input.status === "number" ? input.status : void 0;
202
+ var param = void 0;
203
+ var blobs = [];
204
+ var sources = [input.error, input.body && input.body.error, input.body, input];
205
+ for (var i = 0; i < sources.length; i++) {
206
+ var e = sources[i];
207
+ if (!e) continue;
208
+ if (typeof e === "string") {
209
+ blobs.push(e);
210
+ continue;
211
+ }
212
+ if (typeof e !== "object") continue;
213
+ if (param === void 0 && e.param != null) param = e.param;
214
+ if (typeof e.code === "string") blobs.push(e.code);
215
+ if (typeof e.type === "string") blobs.push(e.type);
216
+ if (typeof e.message === "string") blobs.push(e.message);
217
+ }
218
+ var hay = blobs.join(" | ").toLowerCase();
219
+ if (hay.indexOf("unknown_parameter") !== -1 || hay.indexOf("unknown parameter") !== -1 || hay.indexOf("unsupported_parameter") !== -1 || hay.indexOf("unsupported parameter") !== -1) {
220
+ return true;
221
+ }
222
+ var isClientReqStatus = status === 400 || status === 422;
223
+ if (isClientReqStatus && param != null && param !== "") return true;
224
+ if (isClientReqStatus && hay.indexOf("invalid_request") !== -1 && (hay.indexOf("parameter") !== -1 || hay.indexOf("param") !== -1)) {
225
+ return true;
226
+ }
227
+ return false;
228
+ }
199
229
  function isAuthExpiredError(input) {
200
230
  if (!input) return false;
201
231
  var blobs = [];
@@ -950,10 +980,10 @@ ${options.inlineContentPlaceholder}
950
980
  });
951
981
  };
952
982
  var run = sendAndPoll().catch(function(err) {
953
- if (isAuthExpiredError(err)) return self.host.refreshSession().then(sendAndPoll);
983
+ if (isAuthExpiredError(err) && !isNonRetryableRequestError(err)) return self.host.refreshSession().then(sendAndPoll);
954
984
  throw err;
955
985
  }).then(function(response) {
956
- if (isErrorResponseBody(response) && isAuthExpiredError(response)) {
986
+ if (isErrorResponseBody(response) && isAuthExpiredError(response) && !isNonRetryableRequestError(response)) {
957
987
  return self.host.refreshSession().then(sendAndPoll);
958
988
  }
959
989
  return response;
@@ -1571,7 +1601,7 @@ ${options.inlineContentPlaceholder}
1571
1601
  return getChatHistory({ service: serviceId, owner, platform }, options);
1572
1602
  };
1573
1603
  return Promise.resolve().then(fetchHistory).catch(function(err) {
1574
- if (isAuthExpiredError(err)) return self.host.refreshSession().then(fetchHistory);
1604
+ if (isAuthExpiredError(err) && !isNonRetryableRequestError(err)) return self.host.refreshSession().then(fetchHistory);
1575
1605
  throw err;
1576
1606
  }).then(function(history) {
1577
1607
  if (token !== self.state.gateRefreshToken) return;
package/dist/engine.cjs CHANGED
@@ -195,6 +195,36 @@ function isErrorResponseBody(response) {
195
195
  }
196
196
  return false;
197
197
  }
198
+ function isNonRetryableRequestError(input) {
199
+ if (!input || typeof input !== "object") return false;
200
+ var status = typeof input.status_code === "number" ? input.status_code : typeof input.status === "number" ? input.status : void 0;
201
+ var param = void 0;
202
+ var blobs = [];
203
+ var sources = [input.error, input.body && input.body.error, input.body, input];
204
+ for (var i = 0; i < sources.length; i++) {
205
+ var e = sources[i];
206
+ if (!e) continue;
207
+ if (typeof e === "string") {
208
+ blobs.push(e);
209
+ continue;
210
+ }
211
+ if (typeof e !== "object") continue;
212
+ if (param === void 0 && e.param != null) param = e.param;
213
+ if (typeof e.code === "string") blobs.push(e.code);
214
+ if (typeof e.type === "string") blobs.push(e.type);
215
+ if (typeof e.message === "string") blobs.push(e.message);
216
+ }
217
+ var hay = blobs.join(" | ").toLowerCase();
218
+ if (hay.indexOf("unknown_parameter") !== -1 || hay.indexOf("unknown parameter") !== -1 || hay.indexOf("unsupported_parameter") !== -1 || hay.indexOf("unsupported parameter") !== -1) {
219
+ return true;
220
+ }
221
+ var isClientReqStatus = status === 400 || status === 422;
222
+ if (isClientReqStatus && param != null && param !== "") return true;
223
+ if (isClientReqStatus && hay.indexOf("invalid_request") !== -1 && (hay.indexOf("parameter") !== -1 || hay.indexOf("param") !== -1)) {
224
+ return true;
225
+ }
226
+ return false;
227
+ }
198
228
  function isAuthExpiredError(input) {
199
229
  if (!input) return false;
200
230
  var blobs = [];
@@ -977,10 +1007,10 @@ var ChatSession = class {
977
1007
  });
978
1008
  };
979
1009
  var run = sendAndPoll().catch(function(err) {
980
- if (isAuthExpiredError(err)) return self.host.refreshSession().then(sendAndPoll);
1010
+ if (isAuthExpiredError(err) && !isNonRetryableRequestError(err)) return self.host.refreshSession().then(sendAndPoll);
981
1011
  throw err;
982
1012
  }).then(function(response) {
983
- if (isErrorResponseBody(response) && isAuthExpiredError(response)) {
1013
+ if (isErrorResponseBody(response) && isAuthExpiredError(response) && !isNonRetryableRequestError(response)) {
984
1014
  return self.host.refreshSession().then(sendAndPoll);
985
1015
  }
986
1016
  return response;
@@ -1598,7 +1628,7 @@ var ChatSession = class {
1598
1628
  return getChatHistory({ service: serviceId, owner, platform }, options);
1599
1629
  };
1600
1630
  return Promise.resolve().then(fetchHistory).catch(function(err) {
1601
- if (isAuthExpiredError(err)) return self.host.refreshSession().then(fetchHistory);
1631
+ if (isAuthExpiredError(err) && !isNonRetryableRequestError(err)) return self.host.refreshSession().then(fetchHistory);
1602
1632
  throw err;
1603
1633
  }).then(function(history) {
1604
1634
  if (token !== self.state.gateRefreshToken) return;
@@ -1955,6 +1985,7 @@ exports.getExpiredAttachmentVisiblePath = getExpiredAttachmentVisiblePath;
1955
1985
  exports.groupAttachmentFailures = groupAttachmentFailures;
1956
1986
  exports.isAuthExpiredError = isAuthExpiredError;
1957
1987
  exports.isErrorResponseBody = isErrorResponseBody;
1988
+ exports.isNonRetryableRequestError = isNonRetryableRequestError;
1958
1989
  exports.isOfficeFile = isOfficeFile;
1959
1990
  exports.listClaudeModels = listClaudeModels;
1960
1991
  exports.listOpenAIModels = listOpenAIModels;