Production Errors Differ from Local Errors
Answered
Korat posted this in #help-forum

KoratOP
1. I'm trying to get my errors to be the same on Production as they are on local. I'm getting an error when calling a function that
2. Attached are the relevant code chunks
3. On local, I get the error like I expect which, in this case, is the "email_not_verified" message that I want. On production, I get "An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error."
4. I've tried changing the auth.ts file so that it uses normal error reporting instead of the CustomError class I created, and everything else ChatGPT, Claude, and Gemini could think of, and nothing works. Truly no idea how Next is intercepting my error or how to fix it. When I change from the CustomError class, I just get a message that says "Read more at https://errors.authjs.dev#callbackrouteerror"
The flow, btw, is the CredentialsForm calls a server action (CredentialsSignIn) that calls the signIn method from "@/auth". Then, in the auth.ts file, that's where the signin tries to happen, and on local it gets to the point where it checks if their email_verified is true and throws the error just fine. But on prod, it doesn't. Any help would be greatly appreciated.
2. Attached are the relevant code chunks
3. On local, I get the error like I expect which, in this case, is the "email_not_verified" message that I want. On production, I get "An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error."
4. I've tried changing the auth.ts file so that it uses normal error reporting instead of the CustomError class I created, and everything else ChatGPT, Claude, and Gemini could think of, and nothing works. Truly no idea how Next is intercepting my error or how to fix it. When I change from the CustomError class, I just get a message that says "Read more at https://errors.authjs.dev#callbackrouteerror"
The flow, btw, is the CredentialsForm calls a server action (CredentialsSignIn) that calls the signIn method from "@/auth". Then, in the auth.ts file, that's where the signin tries to happen, and on local it gets to the point where it checks if their email_verified is true and throws the error just fine. But on prod, it doesn't. Any help would be greatly appreciated.
Answered by Korat
Ugh, took a break and watched some YouTube. Ran across a video that explained the problem. Basically I just had to change my server action to use a try catch block so that it could catch the error from the auth.ts file, then return that error in a Promise. From there, I was able to change my client component to recieve that response and handle it as needed.
1 Reply

KoratOP
Ugh, took a break and watched some YouTube. Ran across a video that explained the problem. Basically I just had to change my server action to use a try catch block so that it could catch the error from the auth.ts file, then return that error in a Promise. From there, I was able to change my client component to recieve that response and handle it as needed.
Answer