@oisin-ee/pi-tiers 0.9.2 → 0.9.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/policy.ts +13 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oisin-ee/pi-tiers",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "Sticky virtual model tiers with quota-aware recovery for pi.",
5
5
  "keywords": [
6
6
  "pi-extension",
package/src/policy.ts CHANGED
@@ -15,7 +15,9 @@ interface Target {
15
15
 
16
16
  const ZERO = 0,
17
17
  ONE = 1,
18
+ INTERNAL = 500,
18
19
  BAD_GATEWAY = 502,
20
+ GATEWAY_TIMEOUT = 504,
19
21
  UNAVAILABLE = 503,
20
22
  BAD_REQUEST = 400,
21
23
  UNAUTHORIZED = 401,
@@ -55,6 +57,17 @@ const ZERO = 0,
55
57
  ) {
56
58
  return "quota";
57
59
  }
60
+ // A provider-side failure of one target (HTTP 500/504, an empty upstream stream) is not
61
+ // It is not the request's fault, so the next target in the tier may succeed.
62
+ if (
63
+ status === INTERNAL ||
64
+ status === GATEWAY_TIMEOUT ||
65
+ /\b(?:status|code|HTTP)\s*:?\s*(?:500|504)\b|internal_server_error|server_error|empty_stream/iu.test(
66
+ message,
67
+ )
68
+ ) {
69
+ return "transient";
70
+ }
58
71
  return /overloaded|timeout|timed out|websocket.*1006|server_busy|retry after/iu.test(message)
59
72
  ? "transient"
60
73
  : "request";