Unexpected Token Error: Handling 404 Response in NextJS Application
GET /chat 404 in 1ms
⨯ Error [SyntaxError]: Unexpected token ‘<‘, “)
at parseJSONFromBytes (file:///Users/prathamchauhan/Documents/Next-Projects/chat-with-pdf/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
at successSteps (file:///Users/prathamchauhan/Documents/Next-Projects/chat-with-pdf/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
at eval (file:///Users/prathamchauhan/Documents/Next-Projects/chat-with-pdf/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
at (node:internal/process/task_queues:140:7)
at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
⨯ Error [ERR_HTTP_HEADERS_SENT]: Cannot append headers after they are sent to the client
at ServerResponse.appendHeader (node:_http_outgoing:759:11)
at AsyncLocalStorage.run (node:async_hooks:346:14)
digest: “3422819266”
⚠ Fast Refresh had to perform a full reload due to a runtime error.
✓ Compiled in 365ms (3043 modules)
GET /chat 404 in 1ms
⨯ Error [SyntaxError]: Unexpected token ‘<‘, “)
at parseJSONFromBytes (file:///Users/prathamchauhan/Documents/Next-Projects/chat-with-pdf/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
at successSteps (file:///Users/prathamchauhan/Documents/Next-Projects/chat-with-pdf/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
at eval (file:///Users/prathamchauhan/Documents/Next-Projects/chat-with-pdf/node_modules/next/dist/compiled/edge-runtime/index.js:1:657096)
at (node:internal/process/task_queues:140:7)
at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
⨯ Error [ERR_HTTP_HEADERS_SENT]: Cannot append headers after they are sent to the client
at ServerResponse.appendHeader (node:_http_outgoing:759:11)
at AsyncLocalStorage.run (node:async_hooks:346:14)
digest: “3422819266”
/chat/page.tsx
import { checkPdf } from ‘@/src/actions/existingPdf’
import ChatComponent from ‘@/src/components/ChatComponent’
import { authOptions } from ‘@/src/lib/auth’
import { getServerSession } from ‘next-auth’
import { redirect } from ‘next/navigation’
import React from ‘react’
const page = async() => {
const session = await getServerSession(authOptions)
if(!session){
redirect("/")
}
const response = await checkPdf()
return (
<div>
<ChatComponent name={session.user.name} heading={response===true?true:false}/>
</div>
)
}
export default page
"use server"
import { getServerSession } from "next-auth"
import { authOptions } from "../lib/auth"
import fs from "fs";
import prisma from "@/db";
import { CloseVectorNode } from "@langchain/community/vectorstores/closevector/node";
import { embeddings } from "../constants/embeddings";
export async function checkPdf(){
const session = await getServerSession(authOptions)
if(session.user){
const user = await prisma.user.findUnique({
where: {
id: Number(session.user.id)
}
})
console.log("uuid: ",user?.uuid)
const loadedVectorStore = await CloseVectorNode.loadFromCloud({
uuid:user?.uuid || "",
embeddings,
credentials: {
key: process.env.VOYAGE_ACCESS_KEY,
secret: process.env.VOYAGE_SECRET,
},
});
// Check if the directory exists
if (user?.uuid && user.uuid.trim().length>0) {
return true
} else {
return false
}
}
return false
}
Pratham Chauhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.