agentleFS
charanjit-singhcharanjit-singh/lovable-skills/skills/api-error-handling/SKILL.md

api-error-handling

Skill10 starsChanged 6 months agoMITView on GitHub

Use when standardizing API and edge function errors: HTTP status codes, error JSON shape, logging, or mapping Supabase/Stripe errors to client responses. Not for UI toast copy only or form field validation messages.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use a consistent JSON body:

    line 13
  2. Distinctive:

    Never log passwords, tokens, full card data.

    line 60

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

API error handling

Response shape

Use a consistent JSON body:

{
  "error": "forbidden",
  "message": "You do not have access to this project."
}

Optional details for validation (api-error-handling + server-input-validation).

Codeerror slugWhen
400invalid_inputZod / bad params
401unauthorizedMissing/invalid JWT
403forbiddenAuthenticated, not allowed
404not_foundResource hidden or missing
409conflictUnique violation, duplicate
429rate_limitedToo many requests
500internal_errorUnexpected — generic message to client

Edge helper

function jsonError(status: number, error: string, message: string) {
  return new Response(JSON.stringify({ error, message }), {
    status,
    headers: { "Content-Type": "application/json" },
  });
}

Supabase errors

const { error } = await supabase.from("posts").insert(row);
if (error) {
  if (error.code === "23505") return jsonError(409, "conflict", "Already exists");
  if (error.code === "42501") return jsonError(403, "forbidden", "Not allowed");
  console.error(error);
  return jsonError(500, "internal_error", "Something went wrong");
}

Logging

  • console.error with correlation id (crypto.randomUUID() in response header x-request-id).
  • Never log passwords, tokens, full card data.

Client consumption

Hooks/forms map error slug to toast; show message to users, not raw DB text.

Avoid

  • 200 with { success: false } for errors.
  • Leaking error.message from Postgres in production.
  • Empty catch {} blocks.

Checklist

  • All edge paths return JSON errors, not HTML
  • 500 messages are generic; details in logs only

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.