Skip to content

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

Description

@konomae

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

I modified the middleware to log error.

Before

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

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:

accessToken: process.env.POST_SERVER_ITEM_TOKEN,

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

Is there a way to recommend?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions