UNPKG

@halsp/http

Version:

支持 Halsp HTTP 请求

55 lines (54 loc) 3.08 kB
import { StatusCodes } from "http-status-codes"; import { HttpErrorMessage } from "./http-error-message"; import { Response } from "@halsp/core"; export interface ResultHandler { ok: (body?: unknown) => this; created: (location: string, body?: unknown) => this; accepted: (body?: unknown) => this; noContent: () => this; partialContent: (body?: unknown) => this; redirect: (location: string, code?: StatusCodes.MOVED_PERMANENTLY | StatusCodes.MOVED_TEMPORARILY | StatusCodes.SEE_OTHER | StatusCodes.TEMPORARY_REDIRECT | StatusCodes.PERMANENT_REDIRECT) => this; badRequest: (body?: unknown) => this; badRequestMsg: (error?: HttpErrorMessage | string) => this; unauthorized: (body?: unknown) => this; unauthorizedMsg: (error?: HttpErrorMessage | string) => this; forbidden: (body?: unknown) => this; forbiddenMsg: (error?: HttpErrorMessage | string) => this; notFound: (body?: unknown) => this; notFoundMsg: (error?: HttpErrorMessage | string) => this; methodNotAllowed: (body?: unknown) => this; methodNotAllowedMsg: (error?: HttpErrorMessage | string) => this; notAcceptable: (body?: unknown) => this; notAcceptableMsg: (error?: HttpErrorMessage | string) => this; requestTimeout: (body?: unknown) => this; requestTimeoutMsg: (error?: HttpErrorMessage | string) => this; conflict: (body?: unknown) => this; conflictMsg: (error?: HttpErrorMessage | string) => this; gone: (body?: unknown) => this; goneMsg: (error?: HttpErrorMessage | string) => this; preconditionFailed: (body?: unknown) => this; preconditionFailedMsg: (error?: HttpErrorMessage | string) => this; requestTooLong: (body?: unknown) => this; requestTooLongMsg: (error?: HttpErrorMessage | string) => this; unsupportedMediaType: (body?: unknown) => this; unsupportedMediaTypeMsg: (error?: HttpErrorMessage | string) => this; imATeapot: (body?: unknown) => this; imATeapotMsg: (error?: HttpErrorMessage | string) => this; misdirected: (body?: unknown) => this; misdirectedMsg: (error?: HttpErrorMessage | string) => this; unprocessableEntity: (body?: unknown) => this; unprocessableEntityMsg: (error?: HttpErrorMessage | string) => this; internalServerError: (body?: unknown) => this; internalServerErrorMsg: (error?: HttpErrorMessage | string) => this; notImplemented: (body?: unknown) => this; notImplementedMsg: (error?: HttpErrorMessage | string) => this; badGateway: (body?: unknown) => this; badGatewayMsg: (error?: HttpErrorMessage | string) => this; serviceUnavailable: (body?: unknown) => this; serviceUnavailableMsg: (error?: HttpErrorMessage | string) => this; gatewayTimeout: (body?: unknown) => this; gatewayTimeoutMsg: (error?: HttpErrorMessage | string) => this; httpVersionNotSupported: (body?: unknown) => this; httpVersionNotSupportedMsg: (error?: HttpErrorMessage | string) => this; } export declare function initResultHandler<T extends ResultHandler>(target: T, getRes: (this: any) => Response): void;