-
Notifications
You must be signed in to change notification settings - Fork 0
/
on-request-validation-error.ts
24 lines (19 loc) · 1.05 KB
/
on-request-validation-error.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import type { Request } from 'express';
import type { GenericWsApi } from 'yaschema-ws-api';
interface OnRequestValidationErrorHandlerArgs {
api: GenericWsApi;
expressReq: Request;
invalidPart: 'query';
validationError: string;
}
let globalOnRequestValidationErrorHandler: (args: OnRequestValidationErrorHandlerArgs) => void = () => {};
/** Gets the configured function that will be called whenever a request validation error occurs */
export const getOnRequestValidationErrorHandler = () => globalOnRequestValidationErrorHandler;
/** Sets the configured function that will be called whenever a request validation error occurs */
export const setOnRequestValidationErrorHandler = (handler: (args: OnRequestValidationErrorHandlerArgs) => void) => {
globalOnRequestValidationErrorHandler = handler;
};
/** Triggers the configured function that will be called whenever a request validation error occurs */
export const triggerOnRequestValidationErrorHandler = (args: OnRequestValidationErrorHandlerArgs) => {
globalOnRequestValidationErrorHandler(args);
};