Skip to content

Global error handler displays unnecessary favicon error when a frontend app previously ran on the same port #2

@dev-rashedin

Description

@dev-rashedin

Describe the bug
The globalErrorHandler in express-error-toolkit is built to simplify error handling and remove repetitive middleware boilerplate. However, when the server runs on port 3000 — where a frontend app (like Next.js or React) was previously running — the toolkit displays an unnecessary favicon error message.

Example output:
favicon error
Even the best code breaks sometimes! Let's debug...

🔴 Error Status: 404
🔴 Error Message: Cannot GET /favicon.ico
🟢 Stack Trace (Preview):
c: Cannot GET /favicon.ico
at L (C:\Projects\ai-devScribe\server\node_modules.pnpm\[email protected]\node_modules\express-error-toolkit\dist\index.cjs:1:2392)
at Layer.handleRequest (C:\Projects\ai-devScribe\server\node_modules.pnpm\[email protected]\node_modules\router\lib\layer.js:152:17)

This is not an actual error, but it gets caught and displayed by the global error handler even though the favicon request is harmless.


To Reproduce

  1. Run a frontend app (e.g., Next.js) on port 3000.
  2. Stop the frontend app.
  3. Start an Express server using express-error-toolkit on the same port (3000).
  4. Observe the console/log output — a “favicon error” message appears.

Expected behavior
The globalErrorHandler should ignore favicon.ico 404 errors or handle them silently, as they are not true application errors.


Proposed fix
Add a condition in the global error handler to bypass or filter out errors related to /favicon.ico requests. This will keep the error logs clean and relevant.


Additional context
This occurs when a frontend app was previously served on the same port. The browser still attempts to request /favicon.ico, triggering a false 404 error handled by the toolkit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions