Upstash ratelimitting + trpc

In my project I use upstash/ratelimit (pretty much directly copy / pasted from the how-to) and trpc in my nextjs app. Right now, when people hit the ratelimit I get a TRPC error that says "Unexpected end of JSON" because upstash ratelimitting just redirects to this page (again straight from the tutorial)

import type { NextApiRequest, NextApiResponse } from "next";

export default function handler(_req: NextApiRequest, res: NextApiResponse) {
  res.status(429);
  return res.end();
}


Obviously this doesn't match what TRPC expects. how can I return a TRPC error from this non-trpc api route?
Was this page helpful?