Skip to content

Internal error on paths like '/static/a/abc' if 'a' is a file #80

@AxlLind

Description

@AxlLind

Problem

Accessing a path like static/a/abc will throw an error and respond with status code 500 if a is a file. This is because this generates an ENOTDIR error, instead of ENOENT.

We discovered this since we serve images at static/*.jpg and paths like static/*.jpg/abc returned 500 instead of 404.

Expectation

Should respond with status code 404 and show the 404 page.

Solution

In the code you check forif (err.code !== 'ENOENT'). Adding && err.code !== 'ENOTDIR' for example here makes it correctly respond with 404 instead of 500:

https://github.com/zeit/serve-handler/blob/d1368bf5ece565b27850ceaab2758a5ae0a4579d/src/index.js#L611

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions