Netlify is invoking 404 functions 4 extra times

Hi there,

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.

For example, with the following configuration:

export const config: Config = {
  path: "/api/user",
  method: "GET"
};

If my function returns a statusCode = 404, Netlify tries to invoke :

  1. /api/user.html
  2. /api/user.htm
  3. /api/user/index.html
  4. /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?

Looking forward to your help :pray:

Cheers,
Sidati

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;

I think that’s just the behaviour of the CLI. It doesn’t happen in production.

1 Like

You’re right, just test it on live, seems fine, Thank you

glad to hear it! thanks for writing back in and letting us know your issue was resolved. (: