Last active
August 29, 2022 15:00
-
-
Save KolbySisk/6dd29d88ae4c3f46fe997234f1e58867 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { NextApiRequest, NextApiResponse } from 'next'; | |
type User = { userId: string }; | |
const allowedMethods = ['GET']; | |
const handler = (req: NextApiRequest, res: NextApiResponse<User>) => { | |
try { | |
if (!allowedMethods.includes(req.method!) || req.method == 'OPTIONS') { | |
return res.status(405).send({ message: 'Method not allowed.' }); | |
} | |
return res.status(200).json({ userId: 'abc123' }); | |
} catch (error) { | |
// Catch and log errors - return a 500 with a message | |
console.error(error); | |
Sentry.captureException(error); | |
res.status(500).send({ message: 'Server error!' }); | |
} | |
}; | |
export default handler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment