MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / parseS3Error

Function parseS3Error

packages/filesystem/s3/client.ts:99–125  ·  view source on GitHub ↗

从 S3 响应解析错误信息

(response: Response)

Source from the content-addressed store, hash-verified

97
98/** 从 S3 响应解析错误信息 */
99async function parseS3Error(response: Response): Promise<S3Error> {
100 // 状态码到错误名称的映射(用于 HEAD 等无响应体的请求)
101 const statusCodeMap: Record<number, string> = {
102 301: "PermanentRedirect",
103 400: "BadRequest",
104 403: "AccessDenied",
105 404: "NotFound",
106 409: "Conflict",
107 };
108
109 try {
110 const text = await response.text();
111 if (text) {
112 const parser = new XMLParser();
113 const parsed = parser.parse(text);
114 const error = parsed.Error;
115 if (error?.Code) {
116 return new S3Error(String(error.Code), String(error.Message || response.statusText), response.status);
117 }
118 }
119 } catch {
120 // 解析失败则使用状态码映射
121 }
122
123 const code = statusCodeMap[response.status] || `HTTP${response.status}`;
124 return new S3Error(code, response.statusText, response.status);
125}
126
127// ---- S3 客户端 ----
128

Callers 1

requestMethod · 0.85

Calls 2

textMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected