feat: 处理状态码

This commit is contained in:
xream
2024-12-12 15:35:19 +08:00
parent d015c7867e
commit 9a3cd4f57c
2 changed files with 6 additions and 2 deletions

View File

@@ -172,7 +172,7 @@ export default async function download(
`Downloading...\nUser-Agent: ${userAgent}\nTimeout: ${requestTimeout}\nProxy: ${proxy}\nInsecure: ${!!insecure}\nURL: ${url}`,
);
try {
const { body, headers } = await http.get({
const { body, headers, statusCode } = await http.get({
url,
...(proxy ? { proxy } : {}),
...(isLoon && proxy ? { node: proxy } : {}),
@@ -180,6 +180,10 @@ export default async function download(
...(proxy ? getPolicyDescriptor(proxy) : {}),
...(insecure ? insecure : {}),
});
$.info(`statusCode: ${statusCode}`);
if (statusCode < 200 || statusCode >= 400) {
throw new Error(`statusCode: ${statusCode}`);
}
if (headers) {
const flowInfo = getFlowField(headers);