Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POST Forms Messages and Validations #70

Merged
merged 1 commit into from
Feb 2, 2017
Merged

Conversation

gibarsin
Copy link
Collaborator

Summary

  • return errors in forms with invalid constraints (via POST calls to the API) as a JSON body with the errors mapped as "field":"message"
  • return a 400 Bad Request code in case a field in the Path Params and the Query Params (via GET calls to the API) instead of returning a 500 Internal Server Error with a 404 Not found body message
  • return a 400 Bad Request code in forms with invalid constraints instead of a 500 Internal Server Error
  • added custom (spanish) messages for constraints validation errors

Examples

In case a POST request to /api/v1/students is made with the following JSON:

{"dni":12345686}

The JSON body returned will be:

{ errors: [ {"lastName":"no debe ser nulo"}, {"password":"no debe estar vacío"}, {"firstName":"no debe ser nulo"}, ] }

Known Issues

  • There are issues when returning accent marks in the response body. This may happen because it is not returning the response in UTF-8.
  • According to the RFC, when doing a GET request, the parameters must be given as Query Parameters (in the URL). In the current implementation, the validation messages are returned correctly, however the field value is returned as argX, being X the number of argument, instead of the field name. The reason is that the constraint validations don't have the name of the field in runtime in the case of the PathParams / QueryParams. Having spent much time with that issue, there may exist a workaround, which will appear in another PR.

For example, if a GET request to /api/v1/students?docket=0 is made, the JSON returned is:

{ errors: [ {"arg0":"debe ser igual o mayor a 1"},] }

Trello Card

https://trello.com/c/gx6o7nwX/14-manejo-de-errores-de-form-y-excepciones

@gibarsin
Copy link
Collaborator Author

@MatiasComercio was assigned to see the examples and to read known issues that are independent of the Front End and will crash against them.

.append("\n");
}
responseEntity.append("] }");
return Response.ok().status(Response.Status.BAD_REQUEST).entity(responseEntity.toString()).build();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the Response build with ok()?

- return errors in forms with invalid constraints (via POST calls to the API) as a JSON body with the errors mapped as "field":"message"
- return a 400 Bad Request code in case a field in the Path Params and the Query Params (via GET calls to the API) instead of returning a 500 Internal Server Error with a 404 Not found body message
- return a 400 Bad Request code in forms with invalid constraints instead of a 500 Internal Server Error
- added custom (spanish) messages for constraints validation errors
@gibarsin
Copy link
Collaborator Author

gibarsin commented Feb 2, 2017

@MatiasMercado changes requested have been made. Accept the PR

@gibarsin gibarsin merged commit 324b9fb into development Feb 2, 2017
@gibarsin gibarsin deleted the formsAndExceptions branch February 2, 2017 21:57
MatiasComercio pushed a commit that referenced this pull request Feb 5, 2017
- return errors in forms with invalid constraints (via POST calls to the API) as a JSON body with the errors mapped as "field":"message"
- return a 400 Bad Request code in case a field in the Path Params and the Query Params (via GET calls to the API) instead of returning a 500 Internal Server Error with a 404 Not found body message
- return a 400 Bad Request code in forms with invalid constraints instead of a 500 Internal Server Error
- added custom (spanish) messages for constraints validation errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants