An error occurred in the Server Components render.
Unanswered
Oriental posted this in #help-forum
OrientalOP
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.
I need to show the error, but next skips it. Is there a way not to do it?
I need to show the error, but next skips it. Is there a way not to do it?
13 Replies
@Oriental 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.
I need to show the error, but next skips it. Is there a way not to do it?
you can catch the error serverside via try/catch and always return an object (maybe with the error in it). Keep in mind, that sensitive details might be leaked throught this. You should handle expected errors correctly
OrientalOP
my axios instance is:
export const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL ?? defaultAPI,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
axiosInstance.interceptors.response.use(
(response: AxiosResponse) => {
if (response.data.mensajeError) {
const ERROR_MESSAGE = response.data.mensajeError;
if (IGNORED_CODE_ERRORS.some((code) => ERROR_MESSAGE.includes(code))) {
return response.data;
}
return Promise.reject(new Error(ERROR_MESSAGE));
}
return response.data.response;
},
(error: AxiosError) => {
return Promise.reject(new Error(error.message));
}
);
and use:
export async function postLogin(data: TData) {
const body = {
acceso: data,
plataforma: process.env.NEXT_PUBLIC_PLATFORM_VERSION,
};
return axiosInstance.post("/aulogin", body);
}
and my client component use async function try catch, and toast with error.message. in local server is ok, in production dont show message.
export const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL ?? defaultAPI,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
axiosInstance.interceptors.response.use(
(response: AxiosResponse) => {
if (response.data.mensajeError) {
const ERROR_MESSAGE = response.data.mensajeError;
if (IGNORED_CODE_ERRORS.some((code) => ERROR_MESSAGE.includes(code))) {
return response.data;
}
return Promise.reject(new Error(ERROR_MESSAGE));
}
return response.data.response;
},
(error: AxiosError) => {
return Promise.reject(new Error(error.message));
}
);
and use:
export async function postLogin(data: TData) {
const body = {
acceso: data,
plataforma: process.env.NEXT_PUBLIC_PLATFORM_VERSION,
};
return axiosInstance.post("/aulogin", body);
}
and my client component use async function try catch, and toast with error.message. in local server is ok, in production dont show message.
@Oriental my axios instance is:
export const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_API_URL ?? defaultAPI,
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
});
axiosInstance.interceptors.response.use(
(response: AxiosResponse) => {
if (response.data.mensajeError) {
const ERROR_MESSAGE = response.data.mensajeError;
if (IGNORED_CODE_ERRORS.some((code) => ERROR_MESSAGE.includes(code))) {
return response.data;
}
return Promise.reject(new Error(ERROR_MESSAGE));
}
return response.data.response;
},
(error: AxiosError) => {
return Promise.reject(new Error(error.message));
}
);
and use:
export async function postLogin(data: TData) {
const body = {
acceso: data,
plataforma: process.env.NEXT_PUBLIC_PLATFORM_VERSION,
};
return axiosInstance.post("/aulogin", body);
}
and my client component use async function try catch, and toast with error.message. in local server is ok, in production dont show message.
did you added your .env variables to your hosting provider as well? Either while pushing it directly to github or by adding them to your hosting provider?
OrientalOP
if it is configured. Everything works correctly, but if I want to see an error in production like: 'wrong key' I get the next message. The errors are handled by the API, so I need to disable this next action. can you come to a meet?
@Oriental if it is configured. Everything works correctly, but if I want to see an error in production like: 'wrong key' I get the next message. The errors are handled by the API, so I need to disable this next action. can you come to a meet?
can you
console.log your key to see if you really recieve the correct .env variable?OrientalOP
yes , and when insert the correctly keys, login is succes
I just need to skip this next action or disable it from skipping the error in production
@Oriental when you have your function like this:
Like that you always return data and maybe even the error. Keep in mind, that when your tokens are already public there is no need to have an extra layer of server action around your fetch. You can directly call your fetch from your client.
'use server'
const yourAction = () => {
const myRequest = await fetch("...");
if(!myRequest.ok) {
return {
error: await myRequest.text()
}
} else {
return {
data: await myRequest.json()
}
}
}Like that you always return data and maybe even the error. Keep in mind, that when your tokens are already public there is no need to have an extra layer of server action around your fetch. You can directly call your fetch from your client.
OrientalOP
It doesn't work, I don't really understand how to make it work. do you have a time? for meeting ?
@Oriental It doesn't work, I don't really understand how to make it work. do you have a time? for meeting ?
can you share a reproduction of your issue that also shows the error so we can help you further. For example via github or https://codesandbox.io/
OrientalOP
for example:
in local server my error is :
'invalid user or credentials '
and promove code to production this error is:
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details.
in local server my error is :
'invalid user or credentials '
and promove code to production this error is:
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details.
@Oriental for example:
in local server my error is :
'invalid user or credentials '
and promove code to production this error is:
An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details.
yes, I understood your issue and your issue can be solved by this: https://nextjs-forum.com/post/1329464520749355081#message-1329472444498710549
However, you still have issues. To solve these "other" issues as well, provide a repro
However, you still have issues. To solve these "other" issues as well, provide a repro
@Orientaldid you already created it?