Skip to content

Using getRequestEvent inside HandleServerError hook fails #13654

@filiabel

Description

@filiabel

Describe the bug

I am wondering if there's a particular reason getRequestEvent is not available in HandleServerError hook? I would expect it to work here along side the other server function and handles.

Can only read the current request event inside functions invoked during `handle`, such as server `load` functions, actions, and server endpoints.

Thanks 🙌

Reproduction

Example in hooks.server.js. Visit invalid page e.g. /invalid.
https://stackblitz.com/edit/sveltejs-kit-template-default-wwnmlhej?file=src%2Fhooks.server.js

Logs

Error: Can only read the current request event inside functions invoked during `handle`, such as server `load` functions, actions, and server endpoints.
    at getRequestEvent (/home/projects/sveltejs-kit-template-default-wwnmlhej/node_modules/@sveltejs/kit/src/runtime/app/server/event.js:37:9)
    at Object.handleError (/home/projects/sveltejs-kit-template-default-wwnmlhej/src/hooks.server.js:7:67)
    at handle_error_and_jsonify (/home/projects/sveltejs-kit-template-default-wwnmlhej/node_modules/@sveltejs/kit/src/runtime/server/utils.js:73:30)
    at respond_with_error (/home/projects/sveltejs-kit-template-default-wwnmlhej/node_modules/@sveltejs/kit/src/runtime/server/page/respond_with_error.js:97:67)
    at async resolve (/home/projects/sveltejs-kit-template-default-wwnmlhej/node_modules/@sveltejs/kit/src/runtime/server/respond.js:442:16)
    at async respond (/home/projects/sveltejs-kit-template-default-wwnmlhej/node_modules/@sveltejs/kit/src/runtime/server/respond.js:261:22)
    at async eval (file:///home/projects/sveltejs-kit-template-default-wwnmlhej/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:564:22)

System Info

Latest versions, see Stackblitz above

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions