# Backend & API Debugging: Server Errors, Database Issues & Logs
A 500 error means your server code threw an unhandled exception. The error is in your logs, not in the browser.
// app/api/users/route.ts — BAD: silent failures
export async function GET() {
const users = await prisma.user.findMany();
return Response.json(users);
}
// If prisma throws, the user sees a generic 500 with no details
// GOOD: structured error handling
export async function GET() {
try {
const users = await prisma.user.findMany();
return Response.json(users);
} catch (error) {
console.error('[GET /api/users] Database error:', {
message: error instanceof Error ? error.message : 'Unknown error',
stack: error instanceof Error ? error.stack : undefined,
timestamp: new Date().toISOString(),
});
return Response.json(
{ error: 'Failed to fetch users' },
{ status: 500 }
);
}
}Upgrade to Pro to access the full content
What you'll learn: