-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathparameter-validation-error.ts
More file actions
37 lines (35 loc) · 1.26 KB
/
parameter-validation-error.ts
File metadata and controls
37 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { ErrorObject } from "ajv";
import { JSONSchema } from "../types";
/**
* Provides an error interface for handling when a function call has invalid parameters.
*/
export default class ParameterValidationError implements Error {
public name = "ParameterValidationError";
public message: string;
/**
* @param paramIndex The index of the param that for this error (index
* of the param in MethodObject.params).
* @param expectedSchema The expected JSON Schema for the passed in value.
* @param receievedParam The value of the param passed to the method call.
* @param errors The errors recieved by ajv
*/
constructor(
public paramIndex: number | string,
public expectedSchema: JSONSchema,
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
public receievedParam: any,
errors: ErrorObject[]
) {
this.message = [
`Expected param at ${typeof paramIndex === "string" ? "key" : "position"}: `,
paramIndex,
" to match the json schema: ",
JSON.stringify(expectedSchema, undefined, " "),
". The function received instead ",
receievedParam,
".",
"The Validation errors: \n",
JSON.stringify(errors),
].join("");
}
}