Error: An error occurred in the Server Components render. The specific message is omitted in product
Unanswered
Munchkin posted this in #help-forum
MunchkinOP
Found a couple of these posts here but none of them tells you where you can find the logs.
Anyone can help me? i am using selfhosted
Anyone can help me? i am using selfhosted
7 Replies
American Crow
Most likely throwing errors in server actions instead of returning a error message or re-throwing
MunchkinOP
I did try to make a script that would throw the errors back to me but it seems liek that didnt catch it either
"use client";
import { publish } from "@/utils/events";
export async function ErrorHandler(request) {
if (request.error) {
if (request.function === "LoginUser" || request.function === "Registeruser") {
return request;
}
publish("ShowPopUp", {
text: request.error,
visibility: true,
backgroundColor: "rgba(255, 0, 0, 0.5)",
top: "10px",
right: "20px",
});
return;
} else {
return request;
}
}with this being the code it gets stuck on:
export async function Registeruser(email, password, name) {
if (!email) {
return {
function: Registeruser.name,
error: "Email is required",
};
} else if (!password) {
return {
function: Registeruser.name,
error: "Password is required",
};
} else if (!name) {
return {
function: Registeruser.name,
error: "Name is required",
};
}
const account = await createAdminSession();
await account.create(ID.unique(), email, password, name);
const session = await account.createEmailPasswordSession(email, password);
cookies().set(userCookie, session.secret, {
path: "/",
httpOnly: false,
sameSite: "strict",
secure: false,
expires: SetExpiryDate(7),
});
}American Crow
this looks all good
Do the lines below that throw an error?
if (!email) {
return {
function: Registeruser.name,
error: "Email is required",
};
} else if (!password) {
return {
function: Registeruser.name,
error: "Password is required",
};
} else if (!name) {
return {
function: Registeruser.name,
error: "Name is required",
};
}Do the lines below that throw an error?
In general if you want to have proper error management within server actions you can either implement something like
https://joulev.dev/blogs/throwing-expected-errors-in-react-server-actions
or use a package like
https://next-safe-action.dev/
https://joulev.dev/blogs/throwing-expected-errors-in-react-server-actions
or use a package like
https://next-safe-action.dev/
MunchkinOP
Ill take a look at it. It is kind of what i was going for. Thank you.