vercel / og-image

Open Graph Image as a Service - generate cards for Twitter, Facebook, Slack, etc
https://og-image.vercel.app
MIT License
4.05k stars 1.27k forks source link

How to return a 401 error on one endpoint of these? #238

Closed kevinfaveri closed 1 year ago

kevinfaveri commented 1 year ago

I have created a vercel OG endpoint, and want to return a 401 error with a JSON message for the specific error. Anyway to do it?

kevinfaveri commented 1 year ago

There is no res to return, it seems, as the second param next to req is a NextFetchEvent, that obviously does not have the capabilities for returning stuff as expected

styfle commented 1 year ago

You can return new Response()

See the Edge Runtime api here: https://nextjs.org/docs/api-reference/edge-runtime