Skip to content

Commit

Permalink
Service Validations: Returns error message as an array in faked exten…
Browse files Browse the repository at this point in the history
…sions (#4792)

* Returns error message as an array in faked extensions

* Update title and individual message formatting

* Need to preserve original error message behavior for non-Service Validation errors

* Adds humanize-string dependency to api package
  • Loading branch information
cannikin committed Mar 17, 2022
1 parent 84460eb commit eb8503d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"@babel/runtime-corejs3": "7.16.7",
"@prisma/client": "3.11.0",
"crypto-js": "4.1.1",
"humanize-string": "2.1.0",
"jsonwebtoken": "8.5.1",
"jwks-rsa": "2.0.5",
"md5": "2.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/validations/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class ServiceValidationError extends RedwoodError {
code: 'BAD_USER_INPUT',
properties: {
messages: {
[String(value)]: errorMessage,
[String(value)]: [errorMessage],
},
},
}
Expand Down
9 changes: 7 additions & 2 deletions packages/forms/src/FormError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ const FormError = ({
!!error.networkError && Object.keys(error.networkError).length > 0

if (hasGraphQLError) {
rootMessage = error.graphQLErrors[0].message ?? 'Something went wrong.'
rootMessage = error.graphQLErrors[0].message ?? 'Something went wrong'

// override top-level message for ServiceValidation errorrs
if (error.graphQLErrors[0]?.extensions?.code === 'BAD_USER_INPUT') {
rootMessage = 'Errors prevented this form from being saved'
}

const properties = error.graphQLErrors[0].extensions?.[
'properties'
Expand All @@ -69,7 +74,7 @@ const FormError = ({
if (propertyMessages) {
for (const e in propertyMessages) {
propertyMessages[e].forEach((fieldError: any) => {
messages.push(`${e} ${fieldError}`)
messages.push(fieldError)
})
}
}
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5741,6 +5741,7 @@ __metadata:
"@types/split2": 3.2.1
aws-lambda: 1.0.7
crypto-js: 4.1.1
humanize-string: 2.1.0
jest: 27.5.1
jsonwebtoken: 8.5.1
jwks-rsa: 2.0.5
Expand Down

0 comments on commit eb8503d

Please sign in to comment.