You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.5 KiB

import JSONResponseFactory from './JSONResponseFactory.ts'
import {make} from '../../../../di/src/global.ts'
import HTMLResponseFactory from './HTMLResponseFactory.ts'
import ErrorResponseFactory from './ErrorResponseFactory.ts'
import {Rehydratable} from '../../support/Rehydratable.ts'
import DehydratedStateResponseFactory from './DehydratedStateResponseFactory.ts'
import TemporaryRedirectResponseFactory from './TemporaryRedirectResponseFactory.ts'
import {HTTPStatus} from '../../const/http.ts'
import HTTPErrorResponseFactory from './HTTPErrorResponseFactory.ts'
import HTTPError from '../../error/HTTPError.ts'
export function json(value: any): JSONResponseFactory {
return make(JSONResponseFactory, value)
}
export function html(value: string): HTMLResponseFactory {
return make(HTMLResponseFactory, value)
}
export function error(error: Error | string, status: number = 500): ErrorResponseFactory {
if ( typeof error === 'string' ) error = new Error(error)
return make(ErrorResponseFactory, error, status)
}
export function dehydrate(value: Rehydratable): DehydratedStateResponseFactory {
return make(DehydratedStateResponseFactory, value)
}
export function redirect(destination: string): TemporaryRedirectResponseFactory {
return make(TemporaryRedirectResponseFactory, destination)
}
export function http(status: HTTPStatus, message?: string): HTTPErrorResponseFactory {
return make(HTTPErrorResponseFactory, new HTTPError(status, message))
}