Standard libraries that lift up your code.
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.
 
 
 

25 lines
855 B

import {ErrorResponseFactory} from './ErrorResponseFactory'
import {HTTPError} from '../HTTPError'
import {HTTPStatus} from '../../util'
/**
* Helper that generates a new HTTPErrorResponseFactory given the HTTP status and message.
* @param status
* @param message
* @param output
*/
export function http(status: HTTPStatus, message?: string, output: 'json' | 'html' | 'auto' = 'auto'): HTTPErrorResponseFactory {
return new HTTPErrorResponseFactory(new HTTPError(status, message), output)
}
/**
* Response factory that renders the given HTTPError in the specified output format.
*/
export class HTTPErrorResponseFactory extends ErrorResponseFactory {
constructor(
public readonly error: HTTPError,
output: 'json' | 'html' | 'auto' = 'auto', // FIXME xml support
) {
super(error, error.status, output)
}
}