Add better error message to VerificationError
This commit is contained in:
parent
b3b202c9f9
commit
137a3659b7
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@hibas123/jrpcgen",
|
"name": "@hibas123/jrpcgen",
|
||||||
"version": "1.2.5",
|
"version": "1.2.6",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"packageManager": "yarn@3.1.1",
|
"packageManager": "yarn@3.1.1",
|
||||||
|
@ -1,14 +1,24 @@
|
|||||||
|
import { isGeneratorFunction } from "util/types";
|
||||||
|
|
||||||
|
function form_verficiation_error_message(type?: string, field?: string) {
|
||||||
|
let msg = "Parameter verification failed! ";
|
||||||
|
if (type && field) {
|
||||||
|
msg += `At ${type}.${field}! `;
|
||||||
|
} else if (type) {
|
||||||
|
msg += `At type ${type}! `;
|
||||||
|
} else if (field) {
|
||||||
|
msg += `At field ${field}! `;
|
||||||
|
}
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
export class VerificationError extends Error {
|
export class VerificationError extends Error {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly type?: string,
|
public readonly type?: string,
|
||||||
public readonly field?: string,
|
public readonly field?: string,
|
||||||
public readonly value?: any
|
public readonly value?: any
|
||||||
) {
|
) {
|
||||||
super(
|
super(form_verficiation_error_message(type, field));
|
||||||
"Parameter verification failed! " +
|
|
||||||
(type ? "Expected " + type + "! " : "") +
|
|
||||||
(field ? "At: " + field + "! " : "")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user