You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复URL重写Cloudflare Workers的1101异常报错问题

解决Cloudflare Workers Error 1101 Worker threw exception异常问题

Error 1101本质是Worker代码抛出了未捕获的异常,结合你的代码和现象,从以下几个方向排查修复:

1. 替换HTTP协议为HTTPS

你的代码强制将请求协议改为http,现在绝大多数站点都仅支持HTTPS访问,请求HTTP会被目标站拒绝或重定向,直接触发异常。修改协议为HTTPS:

URI.protocol = "https";

2. 添加异常捕获逻辑

fetch请求可能因网络故障、目标站不可达等抛出错误,必须用try/catch捕获异常,避免未捕获错误触发1101:

async function rewriteURL(request) {
    try {
        var URI = new URL(request.url);
        URI.protocol = "https";
        URI.hostname = "urldestinationexample";
        return fetch(URI, request);
    } catch (err) {
        return new Response(`请求失败: ${err.message}`, { status: 500 });
    }
}

3. 补全非目标域名的请求处理

原代码未处理非mynametitle.workers.dev域名的请求,虽然Cloudflare会默认处理,但明确逻辑能避免潜在异常:

addEventListener("fetch", event => {
    let requestURI = new URL(event.request.url);
    if (requestURI.hostname == "mynametitle.workers.dev") {
        event.respondWith(rewriteURL(event.request));
    } else {
        event.respondWith(fetch(event.request));
    }
})

4. 验证目标站点状态

确认urldestinationexample域名是否正常可访问,是否有安全规则(比如WAF、IP限制)拦截Worker的请求。

内容的提问来源于stack exchange,提问作者zouh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 18:45:10