fix(discord): validate deploy retry-after · openclaw/openclaw@4ef6364
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
File tree
extensions/discord/src/monitor
| Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | import { inspect } from "node:util"; |
2 | | -import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime"; |
| 2 | +import { |
| 3 | +parseStrictFiniteNumber, |
| 4 | +parseStrictNonNegativeInteger, |
| 5 | +} from "openclaw/plugin-sdk/number-runtime"; |
3 | 6 | import { formatDurationSeconds } from "openclaw/plugin-sdk/runtime-env"; |
4 | 7 | import { formatErrorMessage } from "openclaw/plugin-sdk/ssrf-runtime"; |
5 | 8 | import { RateLimitError } from "../internal/discord.js"; |
@@ -102,8 +105,7 @@ function readFiniteNumber(value: unknown): number | undefined {
|
102 | 105 | return value; |
103 | 106 | } |
104 | 107 | if (typeof value === "string" && value.trim().length > 0) { |
105 | | -const parsed = Number(value); |
106 | | -return Number.isFinite(parsed) ? parsed : undefined; |
| 108 | +return parseStrictFiniteNumber(value); |
107 | 109 | } |
108 | 110 | return undefined; |
109 | 111 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
@@ -966,6 +966,19 @@ describe("monitorDiscordProvider", () => {
|
966 | 966 | expect(details).toBe(" (status=429, retryAfter=3.2s, scope=route)"); |
967 | 967 | }); |
968 | 968 | |
| 969 | +it("does not parse malformed Discord deploy retry_after values", () => { |
| 970 | +const details = providerTesting.formatDiscordDeployErrorDetails({ |
| 971 | +status: 429, |
| 972 | +rawBody: { |
| 973 | +message: "You are being rate limited.", |
| 974 | +retry_after: "0x2", |
| 975 | +global: false, |
| 976 | +}, |
| 977 | +}); |
| 978 | + |
| 979 | +expect(details).toBe(" (status=429, scope=route)"); |
| 980 | +}); |
| 981 | + |
969 | 982 | it("rejects malformed Discord deploy rate-limit status values", () => { |
970 | 983 | const details = providerTesting.formatDiscordDeployErrorDetails({ |
971 | 984 | status: 429.5, |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。