No fetch handler!

Hello! I am having trouble with my worker. It is an Email Worker for email routing and I am getting the error "No fetch handler!" I was wondering what this error means. I don't think it's an issue with my code, since one of the example email workers is very similar. Maybe I've set it up incorrectly? I've attached my code and the error.
export default {
async email(message, env, ctx) {
try {
// Extract email data
const emailData = {
to: message.to,
from: message.from,
subject: message.headers.get('subject'),
timestamp: new Date().toISOString(),
headers: Object.fromEntries(message.headers),
// Get the email content
content: {
text: await message.text(),
html: await message.html()
}
};

// Forward email data to API
const response = await fetch("my site", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${env.API_KEY}`,
},
body: JSON.stringify(emailData)
});

if (!response.ok) {
console.error(`API request failed: ${response.status} ${response.statusText}`);
}

} catch (error) {
console.error("Error processing email:", error);
}
}
}
export default {
async email(message, env, ctx) {
try {
// Extract email data
const emailData = {
to: message.to,
from: message.from,
subject: message.headers.get('subject'),
timestamp: new Date().toISOString(),
headers: Object.fromEntries(message.headers),
// Get the email content
content: {
text: await message.text(),
html: await message.html()
}
};

// Forward email data to API
const response = await fetch("my site", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${env.API_KEY}`,
},
body: JSON.stringify(emailData)
});

if (!response.ok) {
console.error(`API request failed: ${response.status} ${response.statusText}`);
}

} catch (error) {
console.error("Error processing email:", error);
}
}
}
Sorry in advance if this is some kind of error that is very easy to fix. I am new to Cloudflare
No description
3 Replies
CheeseyPatrick
CheeseyPatrickOP6mo ago
Ok. It's still working even with this error. Sorry for making this post, I feel kinda stupid. I guess this error is not something to worry about
Rhaegal
Rhaegal6mo ago
Cloudflare Workers can be triggered in various ways. export default { async fetch(request, env, ctx) { ... } }: This is the signature for a standard HTTP Worker. It's designed to intercept and respond to HTTP requests (e.g., from a web browser). When a request hits your worker's URL, the Cloudflare runtime looks for this fetch handler to execute. export default { async email(message, env, ctx) { ... } }: This is the signature for an Email Worker. It's specifically designed to be triggered by incoming emails that are routed to it through Cloudflare's Email Routing service. The message object contains the email's data. The "No fetch handler!" error occurs when your worker, which only has an email handler, receives an HTTP request. The runtime tries to find a fetch handler to process the request, doesn't find one, and consequently throws this error.
CheeseyPatrick
CheeseyPatrickOP6mo ago
Ah, that makes sense. It looks like the little code debugger thing in the cloudflare website code editor makes a http request. Thanks for the help!

Did you find this page helpful?