Triggers
A trigger fires before the server processes a request. Triggers can prepare state, write to transient elements, queue outbound HTTP requests, or terminate the request chain by throwing an HTTP response.
Triggers are stored as HTML Microdata items in the database and discovered automatically via selector queries. Any document on the host can contain trigger definitions. Discovery is inheritance-aware: if a schema on your host declares a type with parent set to https://pagelove.org/Trigger, items of that subtype are discovered and run exactly like plain triggers.
Quick example
This trigger fires on every PUT or POST to paths under /blog/ and sends a webhook notification:
<div itemscope itemtype="https://pagelove.org/Trigger">
<meta itemprop="resource" content="/blog/*">
<meta itemprop="method" content="PUT">
<meta itemprop="method" content="POST">
<div itemprop="action" itemscope itemtype="https://pagelove.org/HttpRequest">
<meta itemprop="url" content="https://hooks.example.com/notify">
<meta itemprop="method" content="POST">
</div>
</div>
Request lifecycle
Triggers sit at the beginning of the request lifecycle:
- Request arrives
- Trigger phase — matching triggers execute in order
- Core processing (GET, PUT, POST, DELETE, etc.)
- Processor phase — matching processors execute
- Async dispatch — queued outbound HTTP requests fire
- Response sent
If a trigger throws an HTTP response, steps 3--4 are skipped. The thrown response is returned directly.
Properties
All filter properties are optional. Omitting a filter means "match all."
resource
One or more glob patterns. The trigger fires only when the request path matches at least one pattern.
A trigger sees only canonical paths. A request whose path is not canonical (an empty segment, a . or .. segment, a backslash, a raw control character, or a percent-encoded /, \, ., letter, digit, -, _ or ~) is refused with 400 Bad Request before any trigger runs. The same holds for a MOVE Destination. See authorization rules for the full list.
<meta itemprop="resource" content="/blog/*">
<meta itemprop="resource" content="/news/*">
<meta itemprop="resource" content="/announcements/*">
Multiple resource values are OR'd — any match is sufficient.
method
HTTP methods to match. The trigger fires only when the request method matches one of the listed values. Matching is case-insensitive. GET implies HEAD.
<meta itemprop="method" content="PUT">
<meta itemprop="method" content="POST">
<meta itemprop="method" content="DELETE">
selector
A CSS selector. The trigger fires only when the element targeted by the request appears in the set of elements selected by this selector.
Both the trigger's selector and the request's selector are resolved against the actual document (semantic matching). If the request does not carry a selector (e.g. a plain GET /page), the selector filter is not evaluated and the trigger matches as if the filter were omitted.
<meta itemprop="selector" content="article">
when
A Sessel or JavaScript expression that gates execution. If the expression evaluates to a falsy value (null, false, 0, empty string), the trigger is skipped. Omitting when means the trigger fires whenever its declarative filters match.
A gate is read-only. It can read your data, for example with User.search(), or in Sessel with a ${ … } selector, but it cannot change anything. If a read fails and the gate does not catch the error, the gate fails with it, in either language. A failed read never looks like an empty result. Pagelove.PUT() and Pagelove.DELETE() fail inside a gate, and the request fails with an error saying the gate is read-only. Put writes in the trigger's action or otherwise instead.
<div itemprop="when" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
Context.request.headers["Authorization"] != null
</script>
</div>
The same gate written in JavaScript uses the https://pagelove.org/JavaScript/Module typed item instead — dispatch is by itemtype, not by the <script> tag:
<div itemprop="when" itemscope itemtype="https://pagelove.org/JavaScript/Module">
<script type="module" itemprop="source">
export default function(ctx) {
return ctx.request.method === "PUT";
}
</script>
</div>
The module's default export is called with the request context as its first positional argument — see Context below. this is not bound to anything meaningful for a when gate.
A Sessel gate can also be written as plain text. The text is the Sessel source, so it needs the same @schema line as the example above. Leading and trailing white space is ignored:
<meta itemprop="when" content='@schema Context url("https://pagelove.org/Context"); Context.request.method == "PUT"'>
The text can be the content of a meta element, as here, or the text of any other element, such as <span itemprop="when">…</span>. Empty plain text, or text that is only white space, means there is no gate, so the trigger fires whenever its declarative filters match. A TransitionHandler reads plain text the same way, except that it treats empty text as a mistake.
A gate written as plain text used to be ignored, so the trigger always fired. It is now a Sessel gate. If you wrote a plain-text when before, check that it is a valid Sessel condition: the trigger now runs only when it is truthy, and runs otherwise when it is not. Text that is not valid Sessel, or that fails with an error when it runs, does not skip the trigger. The request fails with status 500 (503 if a password hash was refused as busy and the script does not catch it, see Error handling) and a TriggerError document whose phase is when, and the request's own save does not happen. A gate that throws an HTTPResponse, or that runs out of budget, is answered as Error handling describes.
action
Actions to execute when the trigger fires. Actions execute in document order. Three action types are supported. A trigger needs at least one action or at least one otherwise (see below) — a trigger with neither is skipped:
- Sessel — a synchronous expression with access to
Context.request - JavaScript — a synchronous
export default function(ctx)module with access to the same request context (see Context) - Outbound HTTP request — an asynchronous outbound call, queued for dispatch after the response is sent
<div itemprop="action" itemscope itemtype="https://pagelove.org/JavaScript/Module">
<script type="module" itemprop="source">
export default function(ctx) {
if (ctx.request.path.startsWith("/admin/")) {
throw {
schema_url: "https://pagelove.org/HTTPResponse",
status: 403,
message: "Admin area is restricted"
};
}
return true;
}
</script>
</div>
A JavaScript action's return value is discarded. What it does comes from its side effects: saves with the global Pagelove object (see Writing from JavaScript actions), an outbound request queued elsewhere in the chain, or a thrown HTTPResponse (see Chain termination for the throw shape).
<!-- Sessel action -->
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
Context.request.headers["Authorization"] != null
</script>
</div>
<!-- Outbound HTTP request action -->
<div itemprop="action" itemscope itemtype="https://pagelove.org/HttpRequest">
<meta itemprop="url" content="https://hooks.example.com/notify">
<meta itemprop="method" content="POST">
</div>
otherwise
One or more actions to execute when when evaluates to a falsy value, instead of action. Same action types, same document-order execution, same Context. otherwise is only meaningful alongside a when gate — if when is omitted, otherwise is never evaluated, since there is no falsy case for it to handle.
<div itemprop="when" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
Context.request.headers["Authorization"] != null
</script>
</div>
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">1</script>
</div>
<div itemprop="otherwise" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema HTTPResponse url("https://pagelove.org/HTTPResponse");
throw new HTTPResponse { status: 401, body: "Authorization required" }
</script>
</div>
This is a shorthand for the common "require X, otherwise reject" shape — it saves inverting the when condition and repeating it, and keeps the accepted and rejected paths next to each other in the markup.
Context
Sessel expressions in triggers have access to Context.request:
| Property | Type | Description |
|---|---|---|
Context.request.method |
String | HTTP method (GET, PUT, POST, etc.) |
Context.request.path |
String | Request path |
Context.request.headers |
Map | Request headers |
Context.request.query |
Map | Query string parameters |
Context.request.body |
Map, String, or any JSON value | Request body, parsed by its content type: a map of fields for a form or multipart post, the parsed value for JSON, and the raw string for any other type. An empty or missing body is an empty map. See Reading form fields in the template |
Context.request.rawBody |
String | Request body as unparsed text (null when there is no body) |
Context.response is not available during trigger execution — the response does not exist yet.
JavaScript when/action modules receive the equivalent request context as their first positional argument (conventionally named ctx):
| Property | Type | Description |
|---|---|---|
ctx.request.method |
String | HTTP method (GET, PUT, POST, etc.) |
ctx.request.path |
String | Request path |
ctx.request.headers |
Object | Request headers |
ctx.request.host |
String | The host name |
ctx.request.query |
Object | Query string parameters |
ctx.request.body |
Object, String, or any JSON value | Request body, parsed by its content type as for Context.request.body: an object of fields for a form or multipart post, the parsed value for JSON, and the raw string for any other type. An empty or missing body is an empty object |
ctx.request.rawBody |
String | Request body as unparsed text (undefined when there is no body) |
ctx.request.auth |
Object | Authentication claims, when available. Through the edge proxy these come only from the visitor's session or other checked credentials: the proxy removes any Authorization header the caller sends |
Chain termination
A Sessel action can terminate the trigger chain by throwing an HTTPResponse. The server does not process the request — the thrown response is returned directly to the client.
<div itemscope itemtype="https://pagelove.org/Trigger">
<meta itemprop="method" content="PUT">
<meta itemprop="method" content="POST">
<meta itemprop="method" content="DELETE">
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
@schema HTTPResponse url("https://pagelove.org/HTTPResponse");
if (Context.request.headers["Authorization"] == null) {
throw new HTTPResponse {
status: 403,
message: "<p>Forbidden</p>"
}
}
</script>
</div>
</div>
This is the mechanism for request guards, authentication checks, and access control at the trigger level.
A JavaScript action terminates the chain the same way, by throwing a plain object with schema_url (or itemtype) set to https://pagelove.org/HTTPResponse:
<div itemprop="action" itemscope itemtype="https://pagelove.org/JavaScript/Module">
<script type="module" itemprop="source">
export default function(ctx) {
if (ctx.request.headers["Authorization"] == null) {
throw {
schema_url: "https://pagelove.org/HTTPResponse",
status: 403,
message: "Forbidden"
};
}
}
</script>
</div>
Supported properties on the thrown object: status (defaults to 500), message (fallback body when body is absent; with no message either, the status's standard reason phrase is used, such as Not Found for 404), body, and headers (an object of additional response headers).
Response headers
An HTTPResponse can include custom response headers using the header property with Pair values:
@schema HTTPResponse url("https://pagelove.org/HTTPResponse");
@schema Pair url("https://pagelove.org/Pair");
throw new HTTPResponse {
status: 303,
header: new Pair { key: "Location", value: "/other-page.html" }
}
A header that frames the message or reports what the request cost is never sent, because the server works these out itself: Content-Length, Transfer-Encoding, Connection, X-Budget-Consumed-Ops, X-Budget-Consumed-Memory, X-Budget-Consumed-Time and X-Storage-Consumed. The same holds for a response a @validate, a @write resolver or a method throws. A Content-Type header on a thrown response with a body of its own sets the response's content type, and only that one is sent. When the platform sends its own error document because the thrown response has no body, the header is ignored, so that document stays HTML.
Multiple headers can be set by repeating the header property (it has 0..n cardinality):
throw new HTTPResponse {
status: 200,
body: "Hello
",
header: new Pair { key: "X-Custom", value: "one" },
header: new Pair { key: "Cache-Control", value: "no-cache" }
}
Setting cookies
A trigger sets a cookie by throwing an HTTPResponse with a Set-Cookie header. In Sessel, each Set-Cookie header is one cookie:
@schema HTTPResponse url("https://pagelove.org/HTTPResponse");
@schema Pair url("https://pagelove.org/Pair");
throw new HTTPResponse {
status: 200,
body: "Welcome back
",
header: new Pair { key: "Set-Cookie", value: "theme=dark; Path=/; Max-Age=86400" }
}
In JavaScript, headers takes a string for one cookie or an array of strings for several:
export default function(ctx) {
throw {
schema_url: "https://pagelove.org/HTTPResponse",
status: 200,
body: "<p>Welcome back</p>",
headers: { "Set-Cookie": ["theme=dark; Path=/", "seen=1; Path=/; HttpOnly"] }
};
}
The server checks every cookie before it sends it. It refuses a cookie when:
- it has a
Domainthat is not the page's own host (a parent domain is refused) - its name starts with
pagelove_, in any case, or is__Host-sessionor__Host-passkey-binding, because the platform owns those names - its name is empty or not a valid cookie name
- it contains a control character, such as a line break
- it contains a character that is not ASCII. Encode such characters, for example with
encodeURIComponent
A refused cookie fails the trigger. The visitor gets a 500 error page with an https://pagelove.org/Error item of type CookieRefused, and its message says why.
The server adds Secure when the visitor used HTTPS, and SameSite=Lax when your cookie names no SameSite. You can set HttpOnly, Path, Max-Age, Expires, SameSite and Secure yourself.
Leave out Domain unless you need it. The server checks the page's main host name, so a Domain that names an alias of your host is refused. A cookie with no Domain always works and stays with the host that set it.
Triggers and caching
A response that sets a cookie is never stored by a shared cache. Nor is a GET or HEAD that a matching trigger shaped, even when the trigger does not throw, or one answered by a thrown HTTPResponse. The server sends Cache-Control: private, no-store, so the trigger runs on every request. no-store also stops the visitor's browser storing the response. If your code writes private, max-age=N, the server rewrites it to private, no-store, so a trigger cannot let browsers cache a page privately. A 304 Not Modified for such a page carries private, no-store too.
To let a shared cache store the response, throw an HTTPResponse with your own Cache-Control that has public, max-age or s-maxage. On a page with a matching GET trigger, only a thrown HTTPResponse can do this. A processor's or a composition's Cache-Control does not lift the rule. The shared cache uses s-maxage, when you set it, in place of max-age. If your host sets composed_max_age_seconds, that value replaces the max-age and s-maxage your code chose on a text/html response. For a static-asset type, static_asset_max_age_seconds does the same. For other types, such as JSON or plain text, the host settings change nothing and your code's values stand. A response with a cookie cannot opt back in, and a cookie is always sent with private, no-store.
When you save a page that holds a trigger or processor over HTTP, the edge cache drops every stored page for your host, under any of its aliases. This holds for a write to a whole page and for a write to one element. Saving over a page also empties the cache when the node that handled the save knows the page held a trigger or processor, or cannot tell. It does not empty the cache when the node knows the page held none. A whole-page MOVE over HTTP is judged by its destination as well: it empties the cache when the page it replaces held a trigger or processor. Deleting the element does empty it, as does editing it in place. A page being stored while the purge runs is not kept. Any HTTP delete of a page and any HTTP write that affects a schema also empty the cache, because the database cannot tell from a delete alone whether a trigger or processor went with it. Deleting a binary file empties the cache. Deleting a directory purges every page deleted under it from the edge. If the directory held more than 1,000 pages, the whole cache for your host is emptied instead.
Saving a trigger or processor over WebDAV, or removing one, empties the edge cache in the same way, and so does deleting a page over WebDAV, including a binary file. Copying or moving a page empties it when the destination held a trigger or processor, or the page you copy or move holds one. If the platform cannot read a stored page for a copy, a move or a save, or cannot load your schemas, it empties the cache anyway. To spot trigger and processor types that a schema declares as subtypes, it loads your site's schemas and the system schemas. It does that only to decide whether to empty the cache. WebDAV still does not check what you save against your schemas or rules. Only the cache is cleared. Four WebDAV cases do not empty it: writing a binary file, creating a directory (MKCOL), copying a directory, and a move whose source delete fails after the copy was made. In those cases only the cache entry for each path written is purged. Deleting a directory, or moving one, purges every page deleted under it from the edge, or empties the whole cache for your host if it held more than 1,000 pages. A copy that empties no host-wide cache still purges the cache entry for its destination.
Some HTTP writes of a trigger or processor do not empty the cache: a write over several documents at once, writes inside a BEGIN and COMMIT transaction (including a delete), and a binary PUT over a definition page with no file extension. Such a change applies to other pages the edge cache already holds only when that entry expires (3600 seconds for a plain page with no Cache-Control) or when the cache is cleared.
Cookies set by any of your code are checked by these rules and sent. That covers triggers, processors, a thrown HTTPResponse from a composition method, a validator or a resolver, and writes to Context.response.headers["Set-Cookie"] during composition. A POST without a selector that creates a resource from a template passes them on too.
Writing from triggers
Trigger Sessel actions can write to the database using the Pagelove.PUT(), Pagelove.POST() and Pagelove.DELETE() methods. Import the Pagelove schema first:
JavaScript actions can write too, with the global Pagelove object (see Writing from JavaScript actions below). A when gate, in either language, is read-only: see when.
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Pagelove url("https://pagelove.org/1.0");
@schema Thing url("https://schema.org/Thing");
let item = new Thing { name: "side-effect-doc" };
Pagelove.PUT(item, "/side-effects/record.html")
</script>
</div>
In Sessel, Pagelove.POST(item, path, selector, placement) adds an item to a page. The placement works as it does for JavaScript (see Writing from JavaScript actions). A refused save is an error you can catch with try and catch. The message of a caught Sessel error starts with runtime error: :
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Pagelove url("https://pagelove.org/1.0");
@schema Thing url("https://schema.org/Thing");
try {
Pagelove.POST(new Thing { name: "newest" }, "/things.html", "#list", "prepend")
} catch (e) {
// e.message starts "runtime error: POST returned 416 Range Not Satisfiable: …"
Pagelove.POST(new Thing { name: "newest" }, "/things.html")
}
</script>
</div>
A JavaScript action can also read your data with search() on an imported schema, as a Sessel action can. It takes the same isa and from options. The search runs under the action's budget.
Writing from JavaScript actions
A JavaScript action has a global Pagelove object with three methods:
| Method | What it does | Gives back |
|---|---|---|
Pagelove.PUT(item, path, selector) |
Saves item to the document at path, or in place of the element selector matches in it |
the saved item |
Pagelove.POST(item, path, selector, placement) |
Adds item to the document at path, inside or next to the element selector matches, as placement says |
the saved item, with no address |
Pagelove.DELETE(path, selector) |
Deletes the document at path, or the element selector matches in it |
true |
selector and placement are optional. placement is append (the default, last in the matched element), prepend (first in it), before or after (next to it), the same as in a client's POST request. With no selector, the item goes inside the page's body: append puts it last and prepend first, and before and after need a selector. item is a string of HTML, a DOM element (its outerHTML is saved), or a schema instance. A schema instance can be saved back where it came from without a path, and deleted with Pagelove.DELETE(instance).
An item saved with PUT comes back with its new address. An item added with POST comes back with no address, so saving it again cannot overwrite the container. HTML that describes a Microdata item comes back as that item, and other HTML gives back undefined. You can ignore the result. The same object is available in JavaScript schema methods: see Saving data from JavaScript for the full rules.
Each write goes through the same path as a Sessel action's write, and finishes before the next line of your script runs. If a write is refused, the call throws an Error. You can catch it, for example to make sure something is used only once:
<div itemprop="action" itemscope itemtype="https://pagelove.org/JavaScript/Module">
<script type="module" itemprop="source">
export default function(ctx) {
try {
// A second DELETE of the same element is refused.
Pagelove.DELETE("/challenges.html", "#c1");
} catch (e) {
throw { schema_url: "https://pagelove.org/HTTPResponse", status: 409, message: "Already used" };
}
}
</script>
</div>
If you do not catch it, the save fails the trigger. The client gets a 500 error page with a TriggerError item whose message includes the refusal: Trigger action failed: javascript/module binding threw: POST returned 416 Range Not Satisfiable: … for JavaScript, and runtime error: POST returned 416 Range Not Satisfiable: … for Sessel. If the refusal names another page, such as the page that already holds a unique value, the client reads another page in its place, and the error page does not say which page defines the trigger. The caught error carries the full reason, including that page's path. To control what the client sees instead, catch the error and throw your own HTTPResponse, as the example above does. The client then reads exactly what you throw.
The message of the error is the verb, the status code and its name, then the reason when there is one, for example POST returned 416 Range Not Satisfiable: selector "#nope": selector matched no elements at the request path or any origin. A selector that matches nothing never creates the container. This also shows a placement:
<div itemprop="action" itemscope itemtype="https://pagelove.org/JavaScript/Module">
<script type="module" itemprop="source">
export default function(ctx) {
try {
Pagelove.POST("<li>Newest</li>", "/notes.html", "#notes", "prepend");
} catch (e) {
// e.message is "POST returned 416 Range Not Satisfiable: …"
Pagelove.POST("<ul id=\"notes\"><li>Newest</li></ul>", "/notes.html");
}
}
</script>
</div>
A PUT to ctx.request.path replaces the request body, like the Sessel body transformation.
A JavaScript action cannot commit Context: Pagelove.PUT(…, "https://pagelove.org/Context") throws. So an action can never change who the caller is. It can set response headers and cookies by throwing an HTTPResponse (see Setting cookies).
Pagelove is not available in a JavaScript when gate. Gates are read-only: a JavaScript schema method called from a Sessel gate has a Pagelove object, but every save it makes throws.
Side-effect writes
Pagelove.PUT(item, "/path.html") writes a document to the specified path. The write goes through the normal request pipeline, including schema validation and shape constraints. It is not checked against the host's authorization rules: a trigger writes with the platform's own access.
Body transformation
Pagelove.PUT(item, Context.request.path) writes to the same path as the incoming request. This replaces the request body in-flight — the server processes the transformed content instead of the original. No throw is needed; core processing runs normally on the modified body.
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Pagelove url("https://pagelove.org/1.0");
@schema Article url("https://schema.org/Article");
let transformed = new Article {
name: "transformed-by-trigger"
};
Pagelove.PUT(transformed, Context.request.path)
</script>
</div>
Chaining
Each trigger in the chain sees the body as left by the previous trigger's Pagelove.PUT(). The last writer wins.
Error handling for writes
Saves a trigger action makes also count towards a limit on saves that run inside other saves: see Saves inside saves.
Side-effect writes committed via Pagelove.PUT(item, "/path") are not rolled back if a later trigger throws or errors. Body transformations via Pagelove.PUT(item, Context.request.path) are transient — they are discarded if the chain terminates with a throw or error.
Static vs dynamic properties
Any property on an outbound HTTP request action can be either a static literal or a dynamic Sessel or JavaScript expression:
<!-- Static URL -->
<meta itemprop="url" content="https://hooks.example.com/notify">
<!-- Dynamic URL (Sessel) -->
<div itemprop="url" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
"https://hooks.example.com/" + Context.request.path
</script>
</div>
<!-- Dynamic URL (JavaScript) -->
<div itemprop="url" itemscope itemtype="https://pagelove.org/JavaScript/Module">
<script type="module" itemprop="source">
export default function(ctx) { return "https://hooks.example.com/" + ctx.request.path; }
</script>
</div>
Declarative by default, imperative when needed.
Execution order
Within a single document, triggers execute in document order (top to bottom). When triggers are spread across multiple documents, documents are ordered lexicographically by path. Within each document, triggers execute in document order.
This produces a deterministic total ordering: triggers in /app/auth fire before triggers in /app/logging, and within each document, top to bottom.
Chain termination stops all subsequent triggers, including those from later documents.
Authentication example
A common pattern: a trigger fires on every request to check for a JWT and write identity claims to a transient element:
<div itemscope itemtype="https://pagelove.org/Trigger">
<meta itemprop="method" content="GET">
<meta itemprop="method" content="PUT">
<meta itemprop="method" content="POST">
<meta itemprop="method" content="DELETE">
<div itemprop="when" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
Context.request.headers["Authorization"] != null
</script>
</div>
<div itemprop="action" itemscope itemtype="https://pagelove.org/Sessel">
<script itemprop="source" type="text/sessel">
@schema Context url("https://pagelove.org/Context");
// Decode JWT claims and write to transient identity element
</script>
</div>
</div>
Authentication becomes another trigger — no separate login handler required.
Error handling
Triggers that cannot be read: If the server cannot read your host's triggers because of a database fault, the request fails and nothing is stored. The status is 500 for a corrupt stored page, 504 when the read takes too long, and 503 for any other database failure. The body is the standard error document. The server does not carry on as if you had no triggers, because a trigger may refuse or change the request. It does not remember the failure either, so the next request tries again. Only a damaged page that holds triggers, or that the server cannot show holds none, fails the request. The server finds triggers through the type index, which lists the pages that hold them, and it reads only those pages. A damaged page that holds none is never read by this lookup, so it does not stop other requests. Only a query that reads that page fails, such as a QUERY over the directory it is in or a search that has to read every page. A damaged page that the index lists fails every request through the serving path on your site until you repair it, including a DELETE or PUT meant to repair it. The same happens when a listed page's stored record cannot be decoded, and when the index cannot be used (it is still being built, or its state cannot be read): the server then reads every page, and no page can be shown to hold none. A damaged Schema page fails every serving request on the site that needs the lookup, because the page may declare a Processor, Trigger or transition subtype. Saves made over WebDAV, FUSE or dombase-util still work while it is damaged, so the page can be repaired there. To find damaged pages, run dombase-util integrity check <host>. Repair the page over WebDAV, which does not look for triggers. The same applies when the platform's shared schemas cannot be read because of a database fault, because the server needs them to find triggers of a schema subtype. The status follows the same rule. A shared schema host that is not set up yet, with no channels or version document, is not a fault: the server then uses your host's own schemas. A host with no triggers is not affected, unless the shared schemas cannot be read.
Busy server: If a when gate, action or dynamic outbound request value uses a password hash and the server is too busy to run it, or the server cannot start a thread to run the JavaScript, and the script does not catch it, the request fails with 503 Service Unavailable and a Retry-After: 1 header. The body is the TriggerError document, with status 503. Triggers run before the request's own save, so that save does not happen. Pages an action already saved with Pagelove.PUT, POST or DELETE are kept. A retry runs the trigger again from the start, so a save an action made before the refusal is made again. Put any password hash before any save.
Malformed Microdata: If a trigger cannot be parsed from its Microdata (missing required fields, invalid structure), it is skipped. It does not break the request.
Sessel or JavaScript runtime error: If a when/action expression throws an unhandled error (one that isn't a recognized HTTPResponse shape), the request fails with an HTML Microdata error body describing the failure. Runtime errors are surfaced, not swallowed, regardless of which language raised them. The TriggerError page has no source property, because the page that defines the trigger is another page. The server log names that page, so ask the site's operator if you need to find it.
Code that runs out of time or budget: Sessel and JavaScript in a trigger get what is left of the request's time budget, or 5 seconds if the request has none. The dynamic values of one outbound request share one such limit. Their work also counts against the request's operations budget. JavaScript's memory counts too. Sessel's own steps do not count against memory, but a Liquid template it renders does. A when gate, action or dynamic outbound request value that runs past a limit, for example in an endless loop, is stopped. The request fails with a TriggerError error body (status 500). For JavaScript, the message says the script exceeded its execution timeout or ran out of budget. For Sessel, it names the limit reached, for example operations budget exceeded, time budget exceeded, memory budget exceeded (for a Liquid template it renders), or include depth exceeded when Sessel.execute calls nest more than 32 deep, or when the code reads items nested more than 256 levels deep. A Sessel try/catch cannot catch running out. Code that has run out of operations or time and then finishes, or fails some other way, still fails the trigger, and the message names the limit. That covers JavaScript that catches running out, including the refusal of a nested call to a computed property, method or pipeline stage (the request keeps that refusal even though the charge is given back), and including in a Sessel method, or a property binding (@computed, @read or @write) in either language, that it calls (if it does not catch that, the trigger fails as running out), and Sessel whose time ran out between its time checks, which come every 1,024 steps. If it throws an HTTPResponse instead, that response is sent, and the save still does not happen. A page an action saves with Pagelove.PUT, POST or DELETE is checked against its schema and its shape constraints under the same budget, and that work counts against the request too. A check that runs out stops the action, and the request fails with the TriggerError that names the limit. An outbound request whose values are all fixed runs no code, so it is never stopped. Triggers run before the request's own save, so that save does not happen. Pages an action already saved with Pagelove.PUT, POST or DELETE are kept. In JavaScript, a thrown null, or a thrown InternalError with an empty message, counts as running out of memory, so a trigger that throws either fails the request the same way, with the TriggerError that names the memory budget. A Sessel throw null is an ordinary throw and fails the trigger like any other runtime error. The JavaScript engine throws null when it has no memory left even to build an error, and gives no other sign. The X-Budget-Consumed-* headers on the error include what the trigger used.
See also
- Processors — fire after core processing
- Outbound HTTP requests — async outbound HTTP action
- Transient elements — session-scoped DOM elements
- Sessel language reference — expression language
- JavaScript in schemas — JavaScript as a Pagelove binding language