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

No Error render for custom mime type #201

Open
AmaliaMV opened this issue Jan 2, 2019 · 0 comments
Open

No Error render for custom mime type #201

AmaliaMV opened this issue Jan 2, 2019 · 0 comments

Comments

@AmaliaMV
Copy link

AmaliaMV commented Jan 2, 2019

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

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

No branches or pull requests

1 participant