Skip to content

Commit

Permalink
Merge pull request #253 from axiomhq/handle-next-not-found-and-redire…
Browse files Browse the repository at this point in the history
…ct-errors

fix: handle NEXT_NOT_FOUND & NEXT_REDIRECT errors
  • Loading branch information
dasfmi authored Dec 13, 2024
2 parents 4605a07 + 51bcf62 commit 0f45aec
Show file tree
Hide file tree
Showing 12 changed files with 1,557 additions and 1,296 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,24 @@ Route handlers accept a configuration object as the second argument. This object
- `logRequestDetails`: Accepts a boolean or an array of keys. If you pass `true`, it will add all the request details to the log (method, URL, headers, etc.). If you pass an array of strings, it will only add the specified keys. See [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request/url) and [NextRequest](https://nextjs.org/docs/app/api-reference/functions/next-request) for documentation on the available keys.
- `NotFoundLogLevel`: Override the log level for NOT_FOUND errors. Defaults to `warn`.
- `RedirectLogLevel`: Override the log level for NEXT_REDIRECT errors. Defaults to `info`.
Config example:
```ts
export const GET = withAxiom(
async () => {
return new Response("Hello World!");
},
{ logRequestDetails: ['body', 'nextUrl'] } // { logRequestDetails: true } is also valid
{
logRequestDetails: ['body', 'nextUrl'], // { logRequestDetails: true } is also valid
NotFoundLogLevel: 'error',
RedirectLogLevel: 'debug',
}
);
```
Expand Down
9 changes: 9 additions & 0 deletions examples/logger/app/api/notfound/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AxiomRequest, withAxiom } from 'next-axiom';
import { notFound } from 'next/navigation';

export const runtime = 'nodejs';

// test handling NEXT_NOT_FOUND error
export const GET = withAxiom(async (req: AxiomRequest) => {
return notFound()
});
9 changes: 9 additions & 0 deletions examples/logger/app/api/permanentRedirect/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { AxiomRequest, withAxiom } from 'next-axiom';
import { permanentRedirect } from 'next/navigation';

export const runtime = 'nodejs';

// test handling NEXT_REDIRECT error with status code 308
export const GET = withAxiom(async (req: AxiomRequest) => {
return permanentRedirect('/')
});
10 changes: 10 additions & 0 deletions examples/logger/app/api/redirect/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AxiomRequest, withAxiom } from 'next-axiom';
import { redirect } from 'next/navigation';

export const runtime = 'nodejs';


// test handling NEXT_REDIRECT error
export const GET = withAxiom(async (req: AxiomRequest) => {
return redirect('/')
});
9 changes: 0 additions & 9 deletions jest.config.ts

This file was deleted.

Loading

0 comments on commit 0f45aec

Please sign in to comment.