rollbar-react icon indicating copy to clipboard operation
rollbar-react copied to clipboard

Next.js AppRoute Example: How can we log an error in the middleware

Open konomae opened this issue 10 months ago • 1 comments

Hi, I tried the Next.js App Router example. (#122)

I modified the middleware to log error.

Before

https://github.com/rollbar/rollbar-react/blob/418412deae8ab0f5b733b7cab3c6d81bd5db7a9f/examples/nextjs-approuter/src/app/middleware.ts#L4-L8

After

export function middleware(request: NextRequest) {
  rollbar.configure({ payload: { context: request.nextUrl.pathname } });

  rollbar.error('error!', (err, response) => {
    // insufficient privileges: post_client_item scope is required but the access token only has post_server_item.
    console.log('error', err, response);
  });

  return NextResponse.next();
}

But as commented above, this causes insufficient privileges error.

If I change the server token to a client post token here:

https://github.com/rollbar/rollbar-react/blob/418412deae8ab0f5b733b7cab3c6d81bd5db7a9f/examples/nextjs-approuter/src/rollbar.ts#L15

The middleware can log the error. But should I use the client post token in the middleware?

Is there a way to recommend?

konomae avatar Apr 09 '24 10:04 konomae

I experienced the same problem

alexookah avatar May 10 '24 13:05 alexookah