Group
  • Testing

    Test my API's error paths, not just the happy path

    Write tests for malformed requests, missing auth, and bad input so your API fails safely instead of crashing.

    • Improve quality
    • Debug & fix
    • Intermediate
    • General

Free Prompt

My API endpoints probably work when everything goes right. I want to know what happens when things go wrong. For every API route or server endpoint in my app, write tests that cover the error paths: 1. Requests with missing required fields. 2. Requests with the wrong types (strings where numbers belong, arrays where objects belong). 3. Requests with no authentication token where one is required. 4. Requests with a valid token for a user who shouldn't have access to that resource. 5. Requests with oversized payloads or absurdly long strings. 6. Requests for resources that don't exist (bad IDs, deleted records). For each case, assert two things: the response status code is correct (400, 401, 403, 404 as appropriate) and the response body does not leak a stack trace, internal file paths, SQL errors, or other implementation details. Don't change the endpoint implementations unless a test exposes a genuine crash or information leak. If you find one, stop and show me what you found before fixing it. When finished, run the full suite and give me a summary: which endpoints handled bad input cleanly and which ones returned 500s, stack traces, or unexpected data.

What This Does / How This Helps

This writes tests for the failure modes of your API: bad input, missing auth, wrong users, missing records. It also checks that errors don't leak stack traces or internals to the client. Happy-path testing is what AI tools do by default, and it hides the ways APIs actually break in production. Real users (and bots scanning your app the day you launch) send garbage. An endpoint that 500s on malformed input is a bug farm; one that leaks a stack trace is a security issue. Finding these in a test suite beats finding them in your error logs with real traffic.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts