Search code examples
error-handlingsveltesveltekitsupabase

Unexpected "Internal Error" when accessing my user authorized dashboard after login


I'm encountering an unexpected error in my SvelteKit application when trying to access the /account route as I'm logging in or occasionally on a page refresh.

This error doesn't happen every time and I'm having difficulty figuring out what to do because of the generic response. The error message is a generic "Internal Error," which is standard for any unexpected sveltekit error.

https://www.skanfarming.com.au/account

Error: { "message": "Internal Error" }

Error
    at ae (https://www.skanfarming.com.au/_app/immutable/nodes/1.93df4267.js:1:2399)
    at bt (https://www.skanfarming.com.au/_app/immutable/chunks/index.bb96de48.js:4:2893)
    at new ie (https://www.skanfarming.com.au/_app/immutable/nodes/1.93df4267.js:1:2507)
    at Xt (https://www.skanfarming.com.au/_app/immutable/chunks/scheduler.2895a0cd.js:1:8225)
    at Array.ot (https://www.skanfarming.com.au/_app/immutable/entry/app.17894691.js:1:1680)
    at Array.dt (https://www.skanfarming.com.au/_app/immutable/entry/app.17894691.js:1:6697)
    at bt (https://www.skanfarming.com.au/_app/immutable/chunks/scheduler.2895a0cd.js:1:950)
    at Qt (https://www.skanfarming.com.au/_app/immutable/nodes/0.eda2fa4d.js:3:8435)
    at bt (https://www.skanfarming.com.au/_app/immutable/chunks/index.bb96de48.js:4:3093)
    at new ie (https://www.skanfarming.com.au/_app/immutable/nodes/0.eda2fa4d.js:3:9357)

Steps to Reproduce:

Log in to the application. After successful login, the application automatically redirects to the /account route. The "Internal Error" sometimes occurs especially frequent on the first login or new login, and the error details are logged in the console.

If I log in again afterwards I stop having any problems and it loads as expected.

What I've Tried:

I've tried adding debugging statements (console.log) in the server-side code, but I couldn't narrow down the exact location of the error.

Environment:

"svelte": "^4.2.18", "@sveltejs/kit": "^1.30.4", Node.js version: v20.11.0,

Browser: Chrome and other modern browsers

I'm really stuck on trying to progress with debugging this style of error, as I don't know where I should go about investigating.

Questions:

How can I gain more insights into the error and identify the root cause?

Are there any specific SvelteKit error handling techniques or best practices that could help in this situation?

What are some common causes of unexpected "Internal Error" in SvelteKit applications, and how can I troubleshoot them?

Are there any additional debugging steps or tools I can use to pinpoint the source of the error?

Any guidance or suggestions on how to handle this situation would be greatly appreciated. Thank you in advance!


Solution

  • That link you posted in your reply also links to another page on capturing those errors using "handleError" in your hooks.server.ts

    I use this myself to log the errors into a database, but you can also just console.log() the error to get the "real" error

    export async function handleError({ error }) {
        console.log(error.stack)
    };
    

    Without that you'll just see the 500 | Internal Error message on the client side and nothing in the server console

    With it though you'll see the error stack on the server's console

    Here is an example if I don't have a +page.server.js syntactically correct. The error is on +page.server.js on line 4

    I would imagine that syntax errors are usually the cause of these, OR, if you are manually throwing errors like throw new Error('message')

    ReferenceError: badType is not defined
        at load (/src/routes/+page.server.js:4:2)
        at Module.load_server_data (/node_modules/@sveltejs/kit/src/runtime/server/page/load_data.js:49:42)
        at eval (/node_modules/@sveltejs/kit/src/runtime/server/page/index.js:150:41)