Skip to content

Commit

Permalink
feat: add trycatch to increment
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorusclarence committed Jan 21, 2022
1 parent 4b18a0c commit 39670e0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/pages/_middleware.ts
Expand Up @@ -24,14 +24,19 @@ export default async function middleware(req: NextRequest) {
}

if (url.link) {
// using fetch because edge function won't allow patch request
await fetch(req.nextUrl.origin + '/api/increment', {
method: 'POST',
body: JSON.stringify(url),
headers: {
'Content-Type': 'application/json',
},
});
try {
// using fetch because edge function won't allow patch request
await fetch(req.nextUrl.origin + '/api/increment', {
method: 'POST',
body: JSON.stringify(url),
headers: {
'Content-Type': 'application/json',
},
});
} catch (error) {
// eslint-disable-next-line no-console
console.error('/api/increment:', { error });
}

return NextResponse.redirect(url.link);
}
Expand Down

0 comments on commit 39670e0

Please sign in to comment.