Missing Error Handling

API route handlers with no try/catch

warningReliabilityerror-handling

Why this matters

An API route with no error handling turns every failed fetch or query into an unhandled 500. The client gets no useful message, and you get no log line you chose. AI tools write the happy path and stop.

Example

Flaggedapp/api/data/route.ts
export async function GET() {
  const res = await fetch("https://api.example.com/data");
  const data = await res.json();
  return Response.json(data);
}
Fixedapp/api/data/route.ts
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 the handler body in try/catch, log the error, and return a response with the right status code.

Reference

In the output
Findings carry "ruleId": "error-handling" in --json and the same id in SARIF and in the terminal.
Silence one line
// prodlint-disable-next-line error-handling
Silence a whole file
// prodlint-disable error-handling at the top of the file
How it works
Matches text patterns. Source on GitHub