// app/api/test/error/route.ts
import { NextRequest, NextResponse } from 'next/server';

export async function GET(request: NextRequest) {
  try {
    // Log the error before throwing
    console.error('Test error endpoint called - throwing intentional error');
    
    // Throw an error
    throw new Error('This is a test error from the API route');
  } catch (error) {
    // Log the caught error with more details
    console.error('Error caught in test route:', {
      message: error instanceof Error ? error.message : 'Unknown error',
      stack: error instanceof Error ? error.stack : undefined,
      timestamp: new Date().toISOString(),
    });
    
    // Return error response
    return NextResponse.json(
      { 
        error: 'Internal Server Error',
        message: 'Test error endpoint triggered'
      },
      { status: 500 }
    );
  }
}

// You can also handle other HTTP methods
export async function POST(request: NextRequest) {
  console.error('POST request to test error endpoint');
  throw new Error('POST method test error');
}