Guides

Unified API response contract for success and error

One envelope, one status code map, and one error field shape for every Campus Answers response. This page audits the surfaces in pack app-campus.site.2, maps each current shape to the corrected shape, and states the validation rules a signed-in app response must follow.

Audit result for this pack

Pack app-campus.site.2 holds public guide pages only. It holds no file under src/app, no route table, and no backend JSON endpoint definition. Every interaction in this pack runs in the browser, saves to local storage on the same device, builds a download, or records an in-memory event. The inconsistency to fix in this slice is therefore the status-only shape on those in-page tools, not a backend envelope, and this change adds no backend file and changes no locked file.

  • Backend JSON endpoints defined in this pack: none
  • In-page tool surfaces audited: six, listed in the mapping table below
  • Current shape on all six: a status line in prose, sometimes with a button label change, and no structured code, no field level error list, and no status code
  • Corrected shape on all six: the envelope below, with the same field limits already stated on each guide

Unified envelope

Use this envelope for every success and every error. Keep the same keys in the same order, keep message in plain instructional wording, and never put a secret, token, question text, search word, or personal detail in any key.

Success

{
  "ok": true,
  "code": "saved",
  "message": "Saved in My Answers.",
  "data": { "id": "item id from the record" },
  "errors": []
}

Error, including validation

{
  "ok": false,
  "code": "validation_failed",
  "message": "Title is required.",
  "data": null,
  "errors": [
    { "field": "sh-title", "code": "required", "message": "Title is required." }
  ]
}
  • ok is a boolean and is true only for success
  • code is a short machine readable string from the status map, repeated in message in plain words for the reader
  • data is null on error and holds the record or rate on success, with counts and rates only and no question text or search words
  • errors is an empty list on success and a list of field, code, and message on error, with field set to the form field id or to null for a form level error
  • When a workspace applies, data also carries workspace, assistant, and channel from the record, with null on a public page with no signed-in workspace, and never omits those keys

Status code map

Use one code for one meaning across every surface. Do not use a success status for an error shape and do not use an error status for a success shape.

Status code, code value, and when to use it
StatusCodeUse
200ok or checked or recordedA read, a check, or a recording completed with no new record
201saved or createdA new saved record was created on this device or in the workspace
400validation_failedA required field is missing, a limit was passed, or a link does not start with https where the guide requires it
403not_permittedThe signed-in role does not cover the step, with the role that can do it named in message
404not_foundNo record with that id exists in that college workspace
409duplicateThe same title, question, source link, workspace, and assistant already exists, with no second copy made
410supersededThe record was merged and stays readable as superseded, with the canonical record id in data
503unavailableA check did not complete or returned no answer text, with no source listed and recorded as unavailable only when a question record was created, never as not answered

A complete check with no supporting passage stays a not-known outcome at 200 with code not_answered in data, separate from unavailable at 503, as stated in Test answers.

Validation rules already stated in this pack

Apply these limits on every surface that takes the same field. Do not add a new limit in this release.

  • Title 200 characters, question 2000, answer 4000, source title 200, source link 500 starting with https, last checked date 80, workspace 120, assistant 120, collection 80, saved date as YYYY-MM-DD or blank
  • Trim leading and trailing space, collapse repeated space for comparison only, and keep the original text for display
  • One error entry per field, in field order, with the first error repeated as the top level message
  • Correcting a field removes its error entry and returns focus to that field
  • A duplicate match updates the same saved item, makes no second copy, and returns 409 with code duplicate and the existing record id in data

Endpoint by endpoint mapping, current versus corrected

Each row is one surface in this pack. Current shape is the shape in the shipped file. Corrected shape is the envelope and status to use for that surface in the next build of that tool.

Current shape versus corrected shape, by surface in pack app-campus.site.2
Surface in this packCurrent shapeCorrected shape
Save answer with sources, save-answer-bundle.htmlStatus prose only, button text changes to Saved in My Answers, duplicate stated in prose with no code201 saved with record id in data, 409 duplicate with existing id in data, 400 validation_failed with field errors for any limit passed
Share copy, share file, share link, and import file, share-answer.htmlStatus prose only, title and link errors stated in prose, no field list, download success stated in prose200 ok with share text or download name in data, 400 validation_failed with sh-title required or sh-source-link invalid_link in errors, same limits as above
Share link decode and save from link, share-answer.html shared previewPreview shown or a prose note that the link could not be read, duplicate stated in prose, no code for an unreadable link200 ok with decoded record in data, 400 validation_failed with field null and code invalid_link for an unreadable link, 409 duplicate with existing id, 201 saved on save
Canonical eligibility check, verified-expert.html canonical-checkResult list in prose with Pass or Needs work per condition, record built as text, Markdown, or JSON downloads with no envelope200 checked with result Eligible or Not eligible and conditions list in data, 400 validation_failed when a required college, assistant, topic, or source title is blank where the check needs it
Weekly quality recording and weekly table, weekly-quality-rate.htmlStatus prose per outcome, weekly table built from in-memory events, CSV download with no envelope, duplicate click ignored in prose201 recorded with event name, rating or outcome or result_bucket, and week_starting_monday_utc in data, 200 ok for the weekly table with counts and rates in data, 409 duplicate for a repeated outcome on the same control, 200 ok for CSV with file name in data
Role first-run progress, role-first-run.htmlProgress prose, alert prose for a missing college name, progress link copied stated in prose, no structured state returned200 ok with checked count, total, completed flag, and snoozed flag in data, 400 validation_failed with rf-college required in errors, progress link returned in data with no progress text sent to a server

No backend row is listed because no backend endpoint is defined in this pack. A future signed-in endpoint must use this same envelope, status map, and error field shape, scoped to one college workspace with the server checking permission on every request.

Checks before you ship a response change

Run each check on a phone and on a desktop with keyboard and screen reader before you publish.

  • Success returns ok true with errors as an empty list, and error returns ok false with data as null and a field list
  • Validation returns 400 with one entry per field in field order, and the first entry matches the top level message
  • Duplicate returns 409 with the existing record id and makes no second copy
  • Unavailable returns 503 with no source listed and is never counted as not answered, and not-known returns 200 with code not_answered
  • No response carries a secret, token, question text, search word, answer text beyond the record being returned, or personal detail in any key
  • Every rate is shown with its numerator and denominator counts, workspace, assistant, channel, and week or date range, with test sessions labeled as test and excluded

Next guide

Test each surface against this contract before approval.