13 lines
347 B
TypeScript
13 lines
347 B
TypeScript
|
|
/**
|
|||
|
|
* 读取错误响应体文本(最多 4096 字符),用于拼入错误信息。
|
|||
|
|
* 若读取失败则返回兜底字符串。
|
|||
|
|
*/
|
|||
|
|
export async function readErrorBody(res: Response): Promise<string> {
|
|||
|
|
try {
|
|||
|
|
const text = await res.text();
|
|||
|
|
return text.slice(0, 4096);
|
|||
|
|
} catch {
|
|||
|
|
return "(unable to read response body)";
|
|||
|
|
}
|
|||
|
|
}
|