File size: 932 Bytes
b1cfe1b
11486ce
 
 
 
 
 
 
 
 
 
 
 
 
b1cfe1b
11486ce
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { readAgentRequestDiagnosticsByLookup } from './diagnostics-route-utils';
import { assertAgentAuthorized } from '@/lib/agent-auth';
import { createRequestId } from '@/lib/agent-state-store';
import { agentErrorResponse, normalizeAgentError } from '@/lib/api-error-response';
import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
    const requestId = createRequestId();
    try {
        assertAgentAuthorized(request.headers);
        const diagnostics = await readAgentRequestDiagnosticsByLookup(request);
        if (!diagnostics) {
            return NextResponse.json({ found: false }, { status: 404, headers: { 'X-Request-Id': requestId } });
        }
        return NextResponse.json({ found: true, diagnostics }, { headers: { 'X-Request-Id': requestId } });
    } catch (error) {
        return agentErrorResponse(normalizeAgentError(error), requestId);
    }
}