Browse Source
Merge pull request #2370 from mslourens/return_validation_errors
Return validation errors
gh-pages
Martin McKeaveney
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
9 additions and
3 deletions
-
packages/builder/src/components/backend/DataTable/modals/CreateEditRow.svelte
-
packages/server/src/api/controllers/row/internal.js
-
packages/server/src/api/index.js
|
|
@ -31,7 +31,12 @@ |
|
|
.flat() |
|
|
.flat() |
|
|
// Prevent modal closing if there were errors |
|
|
// Prevent modal closing if there were errors |
|
|
return false |
|
|
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 }] |
|
|
errors = [{ message: rowResponse.message }] |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
|
|
|
@ -57,7 +57,7 @@ exports.patch = async ctx => { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (!validateResult.valid) { |
|
|
if (!validateResult.valid) { |
|
|
throw validateResult.errors |
|
|
throw { validation: validateResult.errors } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// returned row is cleaned and prepared for writing to DB
|
|
|
// returned row is cleaned and prepared for writing to DB
|
|
|
@ -105,7 +105,7 @@ exports.save = async function (ctx) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if (!validateResult.valid) { |
|
|
if (!validateResult.valid) { |
|
|
throw validateResult.errors |
|
|
throw { validation: validateResult.errors } |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// make sure link rows are up to date
|
|
|
// make sure link rows are up to date
|
|
|
|
|
|
@ -58,6 +58,7 @@ router.use(async (ctx, next) => { |
|
|
ctx.body = { |
|
|
ctx.body = { |
|
|
message: err.message, |
|
|
message: err.message, |
|
|
status: ctx.status, |
|
|
status: ctx.status, |
|
|
|
|
|
validationErrors: err.validation, |
|
|
} |
|
|
} |
|
|
if (env.NODE_ENV !== "jest") { |
|
|
if (env.NODE_ENV !== "jest") { |
|
|
ctx.log.error(err) |
|
|
ctx.log.error(err) |
|
|
|