Skip to content

The error message we are receiving suggests that the string you are attempting to parse as JSON is not valid JSON #6

@SushekTamrakar

Description

@SushekTamrakar

It says "Unexpected token u" in browser error console. The "Unexpected token u" error typically occurs when you try to parse a string that is undefined or null, because the first character of undefined or null is "u".

In your code, it's possible that the lastMessageRaw variable is undefined or null, which is causing the error when you try to parse it as JSON. You can add a null check to make sure that lastMessageRaw has a value before attempting to parse it as JSON.

const [lastMessageRaw] = (await fetchRedis(
'zrange',
`chat:${chatHrefConstructor(session.user.id, friend.id)}:messages`,
-1,
-1
)) as string[]
const lastMessage = JSON.parse(lastMessageRaw) as Message
return {
...friend,
lastMessage,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions