Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/danet/src/deps.ts>Context#assert

A Savory web framework for Deno heavily inspired by Nest
Go to Latest
method Context.prototype.assert
import { Context } from "https://deno.land/x/danet@1.3.3/src/deps.ts";

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 Context type should be used even if it can be inferred from the context.

Example

import { Context, Status } from "https://deno.land/x/oak/mod.ts";

export function mw(ctx: Context) {
  const body = ctx.request.body();
  ctx.assert(body.type === "json", Status.NotAcceptable);
  // process the body and send a response...
}

Parameters

condition: any
optional
errorStatus: ErrorStatus = [UNSUPPORTED]
optional
message: string
optional
props: Record<string, unknown>

Returns

asserts condition