No Error render for custom mime type
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
I am using json view with Custom Mime Types. I have minimal and export mime types.
Additionally, a controller has an action which validates an object.
```
def validate(Pet pet) {
pet.validate()
respond pet
}
```
If I send an object with invalid data to `"$baseUrl/pet/validate"`, the response will be 422 (the expected response). But if I send the same object to `"$baseUrl/pet/validate?format=minimal"`, the response will be 404.
I created this tests to reproduce the issue:
```
void "test validate a property without format"() {
when:
def resp = restBuilder().post("$baseUrl/pet/validate") {
json ([name: 'invalid name'])
}
then:
resp.status == 422
resp.json.errors[0].field == "name"
}
void "test validate a property with specific format"() {
when:
def resp = restBuilder().post("$baseUrl/pet/validate?format=minimal") {
json ([name: 'invalid name'])
}
then:
resp.status == 422 // <-- this fail, the value is 404
resp.json.errors[0].field == "name"
}
```
Apparently, doesn't exist any error render registered to minimal mime type. So, https://github.com/grails/grails-core/blob/a16b4a4274025cc337b3b7dc4463bcad464f2ab9/grails-plugin-rest/src/main/groovy/grails/artefact/controller/RestResponder.groovy#L170 is executed. The same happens with export format.
Here the link to the sample app: https://github.com/AmaliaMV/gsonView-errorWithFormat
Contributor guide
Research direction
Start with grails-plugin-rest/src/main/groovy/grails/artefact/controller/RestResponder.groovy around line 170, then run the two validation reproductions from the issue or the linked sample app. Done means invalid data sent with no format, minimal, and export formats returns 422 with the validation error for the name field instead of 404.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100