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.

CategoryStatus
input422
conflict409
not_found404
forbidden403
transient503
internal500
FieldResult
errors.httpStatuses for OkmError.toHttp. toHttp() uses these when the caller does not pass statuses. toHttp(statuses) replaces them for that call.
errors.includeValuestrue stores row values on the error. They are never logged.
logger.errorReceives { 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

db.ts
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; 
    },
  },
});