return validation errors
This commit is contained in:
parent
dd7edd6f6b
commit
8dfef0d342
|
@ -31,7 +31,10 @@
|
|||
.flat()
|
||||
// Prevent modal closing if there were errors
|
||||
return false
|
||||
} else if (rowResponse.status === 400 || rowResponse.status === 500) {
|
||||
} else if (rowResponse.status === 400 && rowResponse.validationErrors) {
|
||||
errors = Object.keys(rowResponse.validationErrors).map(field => ({message: `${field} ${rowResponse.validationErrors[field][0]}`}))
|
||||
return false
|
||||
} else if (rowResponse.status === 500) {
|
||||
errors = [{ message: rowResponse.message }]
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ exports.patch = async ctx => {
|
|||
})
|
||||
|
||||
if (!validateResult.valid) {
|
||||
throw validateResult.errors
|
||||
throw { validation: validateResult.errors }
|
||||
}
|
||||
|
||||
// returned row is cleaned and prepared for writing to DB
|
||||
|
@ -105,7 +105,7 @@ exports.save = async function (ctx) {
|
|||
})
|
||||
|
||||
if (!validateResult.valid) {
|
||||
throw validateResult.errors
|
||||
throw { validation: validateResult.errors }
|
||||
}
|
||||
|
||||
// make sure link rows are up to date
|
||||
|
|
|
@ -58,6 +58,7 @@ router.use(async (ctx, next) => {
|
|||
ctx.body = {
|
||||
message: err.message,
|
||||
status: ctx.status,
|
||||
validationErrors: err.validation
|
||||
}
|
||||
if (env.NODE_ENV !== "jest") {
|
||||
ctx.log.error(err)
|
||||
|
|
Loading…
Reference in New Issue