x/oak/middleware/serve.ts

A middleware framework for handling HTTP with Deno, Node, Bun and Cloudflare Workers 🐿️ 🦕
Very Popular
Go to Latest
method ServeContext.prototype.assert
import { ServeContext } from "https://dotland-vbqsvsrpfncg.deno-staging.dev/x/oak@v17.1.2/middleware/serve.ts?p=prototype.assert&s=ServeContext";

Asserts the condition and if the condition fails, creates an HTTP error with the provided status (which defaults to 500). The error status by default will be set on the .response.status.

Because of limitation of TypeScript, any assertion type function requires specific type annotations, so the ServeContext type should be used even if it can be inferred from the context.

Parameters

condition: unknown[src]
optional
status: ErrorStatus
[src]
optional
message: string
[src]
optional
props: Record<string, unknown> & Omit<HttpErrorOptions, "status">
[src]

Returns

asserts condition[src]