enh: improve version error information

This commit is contained in:
Ben Allfree
2023-11-16 01:57:19 +00:00
parent f49c7f1ce3
commit f22c0f2b16
2 changed files with 10 additions and 4 deletions

View File

@@ -6,9 +6,12 @@
onModelBeforeCreate((e) => {
const { versions } = require(`${__hooks}/versions.pb.js`)
if (!versions.includes(e.model.get('version'))) {
const version = e.model.get('version')
if (!versions.includes(version)) {
throw new BadRequestError(
`'version' must be one of: ${versions.join(', ')}`,
`Invalid version ${version}. Version must be one of: ${versions.join(
', ',
)}`,
)
}
}, 'instances')

View File

@@ -6,9 +6,12 @@
onModelBeforeUpdate((e) => {
const { versions } = require(`${__hooks}/versions.pb.js`)
if (!versions.includes(e.model.get('version'))) {
const version = e.model.get('version')
if (!versions.includes(version)) {
throw new BadRequestError(
`'version' must be one of: ${versions.join(', ')}`,
`Invalid version ${version}. Version must be one of: ${versions.join(
', ',
)}`,
)
}
}, 'instances')