All files / varjoliitokauppa/app/api/monitoring route.ts

66.66% Statements 6/9
66.66% Branches 4/6
100% Functions 1/1
66.66% Lines 6/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31                  1x 1x 1x       1x 1x               1x            
import { NextResponse } from 'next/server';
import { logError, logEvent } from '@/lib/monitoring';
 
type MonitoringRequest = {
  type?: string;
  [key: string]: unknown;
};
 
export async function POST(request: Request) {
  try {
    const body = (await request.json()) as MonitoringRequest;
    Iif (!body || typeof body !== 'object') {
      return NextResponse.json({ ok: false }, { status: 400 });
    }
 
    const level = body.type === 'client-error' ? 'error' : 'info';
    logEvent(
      {
        source: 'client',
        ...body,
      },
      level
    );
 
    return NextResponse.json({ ok: true });
  } catch (error) {
    logError(error, { source: 'monitoring-endpoint' });
    return NextResponse.json({ ok: false }, { status: 400 });
  }
}