better error message for validation error, fix jest error

This commit is contained in:
einhornimmond 2025-11-24 14:45:34 +01:00
parent 9d4bda53da
commit d9647183c5
2 changed files with 18 additions and 12 deletions

View File

@ -17,17 +17,22 @@ export function validate(schema: ObjectSchema, data: any) {
throw new Error('missing key in config validation with joi: ' + details)
}
const value = err.context.value
const description = schemaJson.keys[key]
? schema.describe().keys[key].flags.description
: 'No description available'
if (data[key] === undefined) {
throw new Error(
`Environment Variable '${key}' is missing. ${description}, details: ${details}`,
)
} else {
throw new Error(
`Error on Environment Variable ${key} with value = ${value}: ${err.message}. ${description}`,
)
try {
const description = schemaJson.keys[key]
? schema.describe().keys[key].flags.description
: 'No description available'
if (data[key] === undefined) {
throw new Error(
`Environment Variable '${key}' is missing. ${description}, details: ${details}`,
)
} else {
throw new Error(
`Error on Environment Variable ${key} with value = ${value}: ${err.message}. ${description}`,
)
}
} catch (e) {
console.error('Error getting description for key ' + key + ': ' + e)
throw e
}
})
}

View File

@ -91,7 +91,8 @@ const getLoggerMocked = mock().mockImplementation((param: any) => {
})
mock.module('log4js', () => ({
getLogger: getLoggerMocked
getLogger: getLoggerMocked,
addLayout: jest.fn()
}))
export function getLogger(name: string) {