Errors
errors.http sets the statuses OkmError.toHttp uses.
errors.http sets the statuses OkmError.toHttp uses.
toHttp() uses these when the caller does not pass statuses. toHttp(statuses) replaces them for that call. A category absent from the map in use keeps the default.
| Category | Status |
|---|---|
input | 422 |
conflict | 409 |
not_found | 404 |
forbidden | 403 |
transient | 503 |
internal | 500 |
| Field | Result |
|---|---|
errors.http | Statuses for OkmError.toHttp. toHttp() uses these when the caller does not pass statuses. toHttp(statuses) replaces them for that call. |
errors.includeValues | true stores row values on the error. They are never logged. |
logger.error | Receives { code, summary }. |
Statuses
The keys are input, conflict, not_found, forbidden, transient, and internal. Each value is a status for that category. One key is enough.
connect stores the map on the error. toHttp() reads it. toHttp(statuses) uses the object from that call. A category absent from that object takes the default status in the table.
Row values
includeValues: true stores row values on the error. values() returns them, or undefined when none were kept. Omitted, or false, stores none.
Never logged
The log record has no row values. logger.error receives { code, summary }. The toHttp body is { code, reason, fields }.
Logger
logger is the option next to errors. error is optional. The argument is { code: string; summary: string }.
Client
import { connect } from "okmodel/pg/postgresjs";
import { schema, table, t } from "okmodel/pg";
const notes = table("notes", {
id: t.identity(),
title: t.text(),
});
const app = schema({ tables: [notes] });
export const db = connect(process.env.DATABASE_URL!, {
schema: app,
errors: {
http: { conflict: 409 },
includeValues: true,
},
logger: {
error(entry) {
void entry.code;
void entry.summary;
},
},
});