UNPKG

1.65 kBTypeScriptView Raw
1import HttpErrors from 'http-errors';
2export declare namespace RestHttpErrors {
3 function invalidData<T, Props extends object = {}>(data: T, name: string, extraProperties?: Props): HttpErrors.HttpError & Props;
4 function unsupportedMediaType(contentType: string, allowedTypes?: string[]): HttpErrors.HttpError<415> & {
5 code: string;
6 contentType: string;
7 allowedMediaTypes: string[];
8 };
9 function missingRequired(name: string): HttpErrors.HttpError;
10 function invalidParamLocation(location: string): HttpErrors.HttpError;
11 const INVALID_REQUEST_BODY_MESSAGE = "The request body is invalid. See error object `details` property for more info.";
12 function invalidRequestBody(details: ValidationErrorDetails[]): HttpErrors.HttpError & {
13 details: ValidationErrorDetails[];
14 };
15 /**
16 * An invalid request body error contains a `details` property as the machine-readable error.
17 * Each entry in `error.details` contains 4 attributes: `path`, `code`, `info` and `message`.
18 * `ValidationErrorDetails` defines the type of each entry, which is an object.
19 * The type of `error.details` is `ValidationErrorDetails[]`.
20 */
21 interface ValidationErrorDetails {
22 /**
23 * A path to the invalid field.
24 */
25 path: string;
26 /**
27 * A single word code represents the error's type.
28 */
29 code: string;
30 /**
31 * A human readable description of the error.
32 */
33 message: string;
34 /**
35 * Some additional details that the 3 attributes above don't cover.
36 */
37 info: object;
38 }
39}