View as Markdown

Refuse in your own handler#

Your rules still apply: the agent receives your status and your JSON, and can correct itself.

Level 1: A person approves with a passkey.
Class write: Something changes and can be undone. The approval can be reused.
routes.append(route("PUT", "/notes/{id}", "notes:write", cls="write", level=1, resource="note:{id}",
                    summary="Change a note", body={"text": "1 to 280 characters"}))


@app.put("/notes/<note_id>")
def change_note(note_id):
    text = str(request.json.get("text", ""))
    if not 1 <= len(text) <= 280:
        return {"error": "text: 1 to 280 characters"}, 422  # the agent gets this status and this JSON
    note = notes.update(g.allowedby.human_id, note_id, text)
    return note or ({"error": "no such note"}, 404)

What the test proves#

  • the app's own refusal reaches the agent as it is: 422 and its JSON; nothing changed
  • a body that is not a JSON object never reaches the app (400); no body at all is a 4xx
  • a note that is not there: the app's 404
  • corrected, the same request is accepted under the same approval: 200
  • 280 emoji are 280 characters in every language: 200; 281: 422