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

Error response body's content type is "text/plain;charset=UTF-8" #2789

Closed
eedijs opened this issue Sep 26, 2022 · 6 comments · Fixed by #2880
Closed

Error response body's content type is "text/plain;charset=UTF-8" #2789

eedijs opened this issue Sep 26, 2022 · 6 comments · Fixed by #2880

Comments

@eedijs
Copy link

eedijs commented Sep 26, 2022

Expected Behavior

Error response body's content-type is application/vnd.api+json, like for all other responses.

Current Behavior

Any kind of error (exception, for example) returns a response body with content type text/plain;charset=UTF-8.

Steps to Reproduce (for bugs)

Trigger an error response - e.g. update an existing entity, but provide an unknown field name, or throw a custom exception that extends Elide's CustomErrorException.

Context

In addition to receiving the wrong content-type in response body, rest assured unit tests are also failing if we're trying to validate the body:

java.lang.IllegalStateException: Expected response body to be verified as JSON, HTML or XML but content-type 'text/plain' is not supported out of the box.
Try registering a custom parser using:
   RestAssured.registerParser("text/plain", <parser type>);

Your Environment

  • Elide version used: 6.1.7
  • Environment name and version (Java 1.8.0_152): Java 11
  • Operating System and version: Windows 10
@aklish
Copy link
Member

aklish commented Sep 28, 2022

This might be related to #2784

Can you reproduce with 6.1.8?

I've tried patching an invalid field, fetching and invalid collection, creating something I don't have permission to. All the errors return the correct content type with 6.1.8:

HTTP/1.1 404 
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Content-Type: application/vnd.api+json
Content-Length: 51
Date: Wed, 28 Sep 2022 02:42:17 GMT
Keep-Alive: timeout=60
Connection: keep-alive

@eedijs
Copy link
Author

eedijs commented Sep 28, 2022

I just tried with version 6.1.8 and it's the same result, but yes - seems like it only for PATCH error response bodies.

One example is patching a random object's attribute:

{"errors":[{"detail":"Unknown attribute random in object"}]}

Response body' content-type was text/plain;charset=UTF-8.

@aklish
Copy link
Member

aklish commented Sep 29, 2022

My bad. This is the same issue as #2784. The fix for that hasn't been released yet. It will be in 6.1.9.

@eedijs
Copy link
Author

eedijs commented Sep 29, 2022

Ok, then we'll have to wait for it, thanks!

@eedijs
Copy link
Author

eedijs commented Feb 1, 2023

Hi @aklish, I've found another issue - the DELETE mappings in JsonApiController class doesn't have content-type set to application/vnd.api+json as well. One case where this could be useful if the DELETE endpoint has to return a JSON error, which then has the text/plain;charset=UTF-8 content-type.

aklish added a commit that referenced this issue Feb 4, 2023
@aklish aklish mentioned this issue Feb 4, 2023
aklish added a commit that referenced this issue Feb 11, 2023
* Fixes #2789

* Added space to test build fix

* Another test

* Another test
@fong81
Copy link

fong81 commented Mar 2, 2023

@aklish could you also fix it in version 6.x.x?

aklish added a commit that referenced this issue Mar 5, 2023
aklish added a commit that referenced this issue Mar 8, 2023
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 a pull request may close this issue.

3 participants