@dwp/govuk-casa
Version:
A framework for building GOVUK Collect-And-Submit-Applications
66 lines (65 loc) • 2.45 kB
TypeScript
/**
* @typedef {import("../casa").ValidateContext} ValidateContext
* @access private
*/
/**
* @typedef {import("../casa").ErrorMessageConfig} ErrorMessageConfig
* @access private
*/
/**
* @typedef {import("../casa").ErrorMessageConfigObject} ErrorMessageConfigObject
* @access private
*/
/**
* @memberof module:@dwp/govuk-casa
* @class
*/
export default class ValidationError {
/**
* Make a ValidationError instance from a primitive object (or a function that
* returns a primitive object) that is specific to the given journey context.
* <br/><br/>
*
* In the case of `errorMsg` being a function, this will be called at runtime,
* at the point that errors are generated within the `validate()`, methods,
* and will be passed the `dataContext`. <br/><br/>
*
* `dataContext` is an object containing the same data passed to all
* validators' `validate()` methods. In the case of `errorMsg` being a
* function, this data is passed to that function in order to help resolve to
* an error message config object.
*
* @param {object} args Arguments
* @param {ErrorMessageConfig} args.errorMsg Error message config to seed
* ValidationError
* @param {ValidateContext} [args.dataContext] Data for error msg function.
* Default is `{}`
* @returns {ValidationError} Error instance
* @throws {TypeError} If errorMsg is not in a valid type
*/
static make({ errorMsg, dataContext }: {
errorMsg: ErrorMessageConfig;
dataContext?: import("../casa").ValidateContext | undefined;
}): ValidationError;
/**
* Create a ValidationError.
*
* @param {string | ErrorMessageConfigObject} errorParam Error configuration
*/
constructor(errorParam?: string | ErrorMessageConfigObject);
/**
* Modifies this instance to reflect the given validation context.
*
* @param {ValidateContext} context See structure above
* @returns {ValidationError} Chain
*/
withContext(context: ValidateContext): ValidationError;
variables: any;
field: string | undefined;
fieldHref: string | undefined;
focusSuffix: any;
validator: string | undefined;
}
export type ValidateContext = import("../casa").ValidateContext;
export type ErrorMessageConfig = import("../casa").ErrorMessageConfig;
export type ErrorMessageConfigObject = import("../casa").ErrorMessageConfigObject;