Next.js Discord

Discord Forum

i am getting issue in server side ..

Unanswered
Griffon Bleu de Gascogne posted this in #help-forum
Open in Discord
Griffon Bleu de GascogneOP

10 Replies

Griffon Bleu de GascogneOP
this code is working
export async function updatePipelineAction(
  data: PipelineUpdateFormSchema
): Promise<UpdateResponseSchema> {
  const token = cookies().get("token")?.value;
  if (!token) {
    console.log("No token found, redirecting to login");
    redirect("/login");
  }

  try {
    const response = await fetch(`${endpoints.pipeline}?id=${data._id}`, {
      method: "PUT",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        title: data.title,
      }),
    });

    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }

    const result = await response.json();
    return result;
  } catch (error) {
    console.error("Error in updatePipelineAction:", error);
    return {
      success: false,
      status: 500,
      data: "",
      message:
        error instanceof Error ? error.message : "Unexpected error occurred",
    };
  }
}
but when i do like this i geeting error
export async function updatePipelineAction(
  data: PipelineUpdateFormSchema
): Promise<UpdateResponseSchema> {
  const token = cookies().get("token")?.value;
  if (!token) {
    console.log("No token found, redirecting to login");
    redirect("/login");
  }

  try {
    console.log("Sending update request", data);
    const response = await ky
      .put(`${endpoints.pipeline}?id=${data._id}`, {
        headers: {
          Authorization: `Bearer ${token}`,
        },
        json: {
          title: data.title,
          users: [],
        },
      })
      .json<UpdateResponseSchema>();

    console.log("Update response:", response);
    return response;
  } catch (error) {
    console.error("Error in updatePipelineAction:", error);
    if (error instanceof HTTPError) {
      const errorText = await error.response.text();
      console.error("HTTP error response:", errorText);
      return {
        success: false,
        status: error.response.status,
        data: "",
        message: errorText || "Invalid title",
      };
    }
    return {
      success: false,
      status: 500,
      data: "",
      message: "Unexpected error occurred",
    };
  }
}
@Griffon Bleu de Gascogne https://codeshare.io/DAYjX3
This error happens really commonly with me\
This is because you are prob using Edge runtime, or executing from middlware
I even get this error when interacting with my database.
If thats not the case, let mw know
Griffon Bleu de GascogneOP
ok
@Griffon Bleu de Gascogne resolved?