Skip to content

Commit 6639f8d

Browse files
Added custom logger library to endpoint.
1 parent 6069b06 commit 6639f8d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/app/api/errors/route.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NextRequest, NextResponse } from 'next/server'
22
import prisma from '@/lib/db'
3-
import { withLogging } from '@/lib/logger'
3+
import { withLogging, logger } from '@/lib/logger'
4+
import { log } from 'console'
45

56
export const POST = withLogging(async (request: NextRequest) => {
67
try {
@@ -18,6 +19,15 @@ export const POST = withLogging(async (request: NextRequest) => {
1819
const { message, stack, platform, options } = errorPayload
1920
const { isFatal, errorInfo } = options || {}
2021

22+
logger.info('Received error report:', {
23+
message,
24+
platform,
25+
isFatal,
26+
errorInfo,
27+
stack: stack || 'No stack trace provided',
28+
originalPayload: errorPayload, // Log the full original payload for auditing
29+
})
30+
2131
const newErrorReport = await prisma.errorReport.create({
2232
data: {
2333
message,
@@ -29,18 +39,17 @@ export const POST = withLogging(async (request: NextRequest) => {
2939
},
3040
})
3141

32-
console.log('Error report logged:', newErrorReport.id)
3342
return NextResponse.json(
3443
{ message: 'Error logged successfully.', reportId: newErrorReport.id },
3544
{ status: 201 }
3645
)
3746
} catch (error) {
3847
// This catches errors in the API endpoint itself
39-
console.error('Failed to save error report:', error)
48+
logger.error('Failed to save error report:', error)
4049

4150
// Avoid using 'error()' as a variable name to prevent shadowing
4251
const e = error as Error
43-
console.error(e.stack)
52+
logger.error(e.stack)
4453

4554
return NextResponse.json(
4655
{ error: 'Internal server error while saving error report.' },

0 commit comments

Comments
 (0)