Skip to content

Add a JSON API to list, read, resolve and delete errors - #125

Open
marostr wants to merge 4 commits into
fractaledmind:mainfrom
marostr:json-api
Open

marostr wants to merge 4 commits into
fractaledmind:mainfrom
marostr:json-api

Conversation

@marostr

@marostr marostr commented Nov 25, 2026 •

Copy link
Copy Markdown

The dashboard is HTML only, so a script or an AI agent that watches production errors has to scrape it or reach into the errors database. This adds the dashboard's four actions as JSON, behind a single key.

  • Off by default. Nothing is exposed until config.solid_errors.api_key (or SOLIDERRORS_API_KEY) is set; until then the API answers 404.
  • One key, sent as a bearer token (Authorization: Bearer <key>), compared with secure_compare. The controller inherits from ActionController::API, not base_controller_class, and ignores username and password, so a dashboard behind basic auth or a custom base controller doesn't lock the API out. Route constraints around the mount still apply, so behind a session constraint such as Devise's authenticate the API can't be reached with a key alone; the README says so and how to mount around it.
  • The dashboard's actions and rules:
    • GET /api/errors: the unresolved errors (or ?scope=resolved), latest occurrence first, with occurrences_count, first_seen_at and last_seen_at
    • GET /api/errors/:id: the error with its markdown (from to_markdown) and a page of its occurrences with filtered backtraces, using the dashboard's page and items
    • PATCH /api/errors/:id: {"error": {"resolved": true}} resolves it now, false reopens it, anything else gets 422
    • DELETE /api/errors/:id: a resolved error only; an unresolved one gets 422 with the dashboard's message
  • Failures in JSON: 401 for a wrong or missing key, 404 for an unknown error, 422 for a bad body.

The API exposes the dashboard's Page to scripts, so Page now treats items and page below one as one (items=0 raised FloatDomainError, page=0 gave a negative offset) and exposes the current page. The 422 is a number because Rack 3.1 deprecates :unprocessable_entity and older Racks don't know :unprocessable_content.

Tests cover each action, bad PATCH bodies, page and items below one, filtered backtraces, a wrong or missing key, the API being off without a key, and an empty api_key falling back to the environment variable. The suite passes on Rails 7.1 and 8.1 and standard is clean. The README documents it under Configuration → JSON API.

We run Solid Errors in production and have an agent check it every half hour; this is what it needed.

The dashboard is HTML only, so a script or an agent that watches
production errors had to scrape it or query the database. The API has
the dashboard's four actions with its rules, behind a single api_key
sent as a bearer token. It is off, answering 404, until the key is set,
and it inherits from ActionController::API rather than
base_controller_class, so a dashboard behind a session sign-in or basic
auth does not lock it out.
A PATCH with resolved_at let any JSON value into the column: a number or
true was stored as is, and an unparseable string reopened the error.
The API now takes {"error": {"resolved": true}} or false and sets the
time itself; anything else, including a missing or non-object error
key, gets a 422.

Failures answer in JSON: the routes default to it, and a wrong key gets
a JSON 401. Occurrence backtraces are filtered to [PROJECT_ROOT] and
[GEM_ROOT] as on the dashboard. Page clamps items and page to at least
one, so items=0 no longer raises and page=0 no longer gives a negative
offset, and exposes the current page. An empty api_key falls back to
SOLIDERRORS_API_KEY. The README says the API can't be reached behind a
session constraint such as Devise's authenticate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant