import { Application } from "./application.ts";import { ServerRequest } from "./deps.ts";import { createHttpError } from "./httpError.ts";import { Request } from "./request.ts";import { Response } from "./response.ts";import { ErrorStatus } from "./types.ts";
export class Context<S extends object = { [key: string]: any }> { app: Application<any>;
request: Request;
response = new Response();
state: S;
constructor(app: Application<S>, serverRequest: ServerRequest) { this.app = app; this.state = app.state; this.request = new Request(serverRequest); }
throw(errorStatus: ErrorStatus, message?: string, props?: object): never { const err = createHttpError(errorStatus, message); if (props) { Object.assign(err, props); } throw err; }}