Next.js Discord

Discord Forum

SyntaxError: Unexpected end of JSON input

Answered
Atlantic mackerel posted this in #help-forum
Open in Discord
Avatar
Atlantic mackerelOP
hey guys, im trying to fetch data to my own api server

I tried this:


'use client'


import {getAccountProfile} from "@/app/api/auth/account/user";

export default async function Home({params}: { params: { uuid: string } }) {
    let res = await getAccountProfile(params.uuid);
    res.json().then((result) => {
        console.log(result)
    })
    return (
        <div className="">
            <div>Hi there!</div>
        </div>
    )
}

but the error said:


[NEXT]  ⨯ unhandledRejection: SyntaxError: Unexpected end of JSON input
[NEXT]     at JSON.parse (<anonymous>)
[NEXT]     at parseJSONFromBytes (node:internal/deps/undici/undici:5419:19)
[NEXT]     at successSteps (node:internal/deps/undici/undici:5390:27)
[NEXT]     at fullyReadBody (node:internal/deps/undici/undici:1501:9)
[NEXT]     at async specConsumeBody (node:internal/deps/undici/undici:5399:7)
[NEXT]  ✓ Compiled /api/auth/[...nextauth] in 132ms (314 modules)

even though on client's logging work just sooo fine (like the photo) but
Why this error has been occurred?
Image
Answered by Jesse677
all you need to do is res.then not res.json().then, can you show the code for getAccountProfile
View full answer

3 Replies

Avatar
all you need to do is res.then not res.json().then, can you show the code for getAccountProfile
Answer
Avatar
did it work @Atlantic mackerel
Avatar
Atlantic mackerelOP
OH yeah sorry I didn't saw that I fix it on my own thank you!! 🙂