|
4 | 4 | readProviderJsonResponse, |
5 | 5 | readResponseTextLimited, |
6 | 6 | } from "openclaw/plugin-sdk/provider-http"; |
| 7 | +import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime"; |
7 | 8 | import { sleep } from "openclaw/plugin-sdk/runtime-env"; |
8 | 9 | import { |
9 | 10 | fetchWithSsrFGuard, |
@@ -94,6 +95,14 @@ function buildMattermostApiUrl(baseUrl: string, path: string): string { |
94 | 95 | return `${normalized}/api/v4${suffix}`; |
95 | 96 | } |
96 | 97 |
|
| 98 | +async function readMattermostSuccessText(res: Response, path: string): Promise<string> { |
| 99 | + const bytes = await readResponseWithLimit(res, MATTERMOST_TEXT_RESPONSE_LIMIT_BYTES, { |
| 100 | + onOverflow: ({ maxBytes }) => |
| 101 | + new Error(`Mattermost API ${path}: text response exceeds ${maxBytes} bytes`), |
| 102 | + }); |
| 103 | + return new TextDecoder().decode(bytes); |
| 104 | +} |
| 105 | + |
97 | 106 | export async function readMattermostError(res: Response): Promise<string> { |
98 | 107 | const contentType = res.headers.get("content-type") ?? ""; |
99 | 108 | if (!res.body) { |
@@ -226,7 +235,7 @@ export function createMattermostClient(params: { |
226 | 235 | if (contentType.includes("application/json")) { |
227 | 236 | return await readProviderJsonResponse<T>(res, `Mattermost API ${path}`); |
228 | 237 | } |
229 | | - return (await readResponseTextLimited(res, MATTERMOST_TEXT_RESPONSE_LIMIT_BYTES)) as T; |
| 238 | + return (await readMattermostSuccessText(res, path)) as T; |
230 | 239 | }; |
231 | 240 |
|
232 | 241 | return { baseUrl, apiBaseUrl, token, request, fetchImpl }; |
|
0 commit comments