Next.js Discord

Discord Forum

Nextjs api 401 prints out console error. Should i use 200?

Unanswered
Whiteleg shrimp posted this in #help-forum
Open in Discord
Whiteleg shrimpOP
I using nextjs api. If my get request successfully fetches from my database i return a 200. if not i return a 401. However, this console logs and error in dev tools.

Should i instead return a 200 even when it doesn't return any data and just put fake data. Or let the error console out?

export default function handler(req, res) {
  if (req.method === 'GET') {
    if (fetchData) {
     return res.status(200).json({data})
     } 
else { return res.status(401.json({}) }
}

0 Replies