I’m encountering an issue with my serverless function on Netlify. When I intentionally return a 404 response (e.g., when a user is not found), Netlify automatically retries the same API endpoint with .html and .htm extensions.
If my function returns a statusCode = 404, Netlify tries to invoke :
/api/user.html
/api/user.htm
/api/user/index.html
/api/user/index.htm
causing the function to be triggered 5 times in total. Since I’m billed for each function invocation, this is a problem.
I tried using the excludedPath config property to exclude the .html/.htm extensions, but it doesn’t seem to resolve the issue. Is there a way to disable these retries?
While that’s expected behaviour when trying to locate a static file, I tried deploying a Function that returns a 404, but I don’t see that behaviour. Could you let us know how to reproduce this issue?
Thanks @hrishikesh for your response. Here’s the code you can test, along with the log I’m seeing when I call SITE_URL/api/hrishikesh (screenshot attached).
import type { Config } from "@netlify/edge-functions";
import type { Handler } from "../types/netlify.js";
const fnHandler: Handler = async (req) => {
console.log(">>", req.url);
return new Response(null, {
status: 404,
});
};
export const config: Config = {
path: "/api/hrishikesh",
method: "GET",
};
export default fnHandler;