Missing Error Handling

Async operations without try/catch

warningReliabilityerror-handling

Why this matters

Unhandled errors in async operations crash your server or show a blank screen to users. AI tools focus on the happy path and skip error handling.

Bad
export async function GET() {
  const res = await fetch("https://api.example.com/data");
  const data = await res.json();
  return Response.json(data);
}
Good
export async function GET() {
  try {
    const res = await fetch("https://api.example.com/data");
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    const data = await res.json();
    return Response.json(data);
  } catch (error) {
    console.error("Failed to fetch data:", error);
    return Response.json(
      { error: "Service unavailable" },
      { status: 503 }
    );
  }
}

How to fix

Wrap every async operation in try/catch. Check response status codes. Return appropriate error responses instead of letting exceptions bubble up.

All rules