Skip to content

Instantly share code, notes, and snippets.

@recursivecodes
Created April 18, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recursivecodes/580cf3e4033804d34bb4a6b250bb5157 to your computer and use it in GitHub Desktop.
Save recursivecodes/580cf3e4033804d34bb4a6b250bb5157 to your computer and use it in GitHub Desktop.
@Post("/save")
HttpResponse<Map> savePerson(@Body Person person) {
try {
return HttpResponse.ok( [ person: personService.save(person) ] as Map )
}
catch(ValidationException e) {
return HttpResponse.unprocessableEntity().body(
[
person: person,
errors: e.errors.allErrors.collect {
FieldError err = it as FieldError
[
field: err.field,
rejectedValue: err.rejectedValue,
message: err.defaultMessage
]
}
]
) as HttpResponse<Map>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment