1
0
Fork 0

feat: include data path in error messages

This commit is contained in:
ssube 2019-09-11 06:49:06 -05:00 committed by Sean Sube
parent 80f2ea6521
commit 67a61f6d8a
1 changed files with 12 additions and 2 deletions

View File

@ -4,8 +4,18 @@ import { VisitorError } from '../../visitor/VisitorError';
export function friendlyError(err: ErrorObject): VisitorError {
return {
data: {},
data: {
err,
},
level: 'error',
msg: err.message || err.keyword,
msg: friendlyErrorMessage(err),
};
}
export function friendlyErrorMessage(err: ErrorObject): string {
if (err.message) {
return `${err.dataPath} ${err.message}`;
} else {
return `${err.dataPath} ${err.keyword}`;
}
}