chore: migrate /api/avatar/[uuid] to App Router (#19514)

* chore: migrate /api/avatar/[uuid]

* fix type

* move location of apiRouteMiddleware and fix the args

* refactor
This commit is contained in:
Benny Joo authored and GitHub committed 2025-02-25 11:19:29 +00:00
1 parent 6ea879f265
commit d1a9af84b2
5 files changed
+35 -28

No files matched your search

-35
View File
@@ -1,35 +0,0 @@
import { captureException } from "@sentry/nextjs";
import { ApiError } from "next/dist/server/api-utils";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { getServerErrorFromUnknown } from "./getServerErrorFromUnknown";
export const apiRouteMiddleware =
(handler: (req: NextRequest, res?: NextResponse) => Promise<NextResponse>) =>
async (req: NextRequest, res: NextResponse) => {
try {
return await handler(req, res);
} catch (error) {
if (error instanceof ApiError) {
return NextResponse.json({ message: error.message }, { status: error.statusCode });
} else {
const serverError = getServerErrorFromUnknown(error);
// we don't want to report Bad Request errors to Sentry / console
if (!(serverError.statusCode >= 400 && serverError.statusCode < 500)) {
console.error(error);
captureException(error);
}
return NextResponse.json(
{
message: serverError.message,
url: serverError.url,
method: serverError.method,
},
{
status: serverError.statusCode,
}
);
}
}
};