Next.js Discord

Discord Forum

Next.js and Prisma(mongo)

Unanswered
MeKa posted this in #help-forum
Open in Discord
There is no problem when I enter the correct id. but there is no problem when it is wrong and matches the ObjectId. but i get this error when i increment a single digit.

64ae0460785ad18eb17729cb => no problem

64ae0460785ad18eb17729cb2 => there is a problem

import React from "react";
import UpdateLocationInfo from "./UpdateLocationInfo";
import NotFound from "@/components/common/NotFound";
import prisma from "@/lib/prisma";

export const dynamic = "force-dynamic";
export const revalidate = 1;

const Home = async ({ params: { id }, }: { params: { id: string } }) => {
    const data = await prisma.locationInfo.findUnique({
        where: {
            id: id
        }
    })

    if (data === null) {
        return <NotFound message={"The location you are looking for was not found!The location you are looking for was not found!"} />;
    }

    return (
        <>
            <UpdateLocationInfo data={data} />
        </>
    );
};
export default Home;



Error =>
Unhandled Runtime Error
Error: 
Invalid `prisma.location.findUnique()` invocation:


Inconsistent column data: Malformed ObjectID: provided hex string representation must be exactly 12 bytes, instead got: "64ae0460785ad18eb17729cb2", length 25.

5 Replies

i guess the error msg is coming from Mongo, saying you passed 25 chars in objectId, where it should be 24 chars.
12 bytes = 24 chars in hex
True, but how can I fix this error? So assuming a wrong ID is coming, I want to meet the error.
it’s up to you. if it’s a service to make million dollars, you want to have input validation, then return 400. or just try catch exception, return not found while emitting system log
it’s your hobby toy project just be careful to pass a param