ExceptionMapper ignores defaultContentType
See original GitHub issueConsider the following snippet:
Javalin app = Javalin.create().defaultContentType("application/json").start(); app.get("/", ctx -> { throw new ForbiddenResponse(); });
The defaultContentType is sent to the client, but the answer is in text/plain.
Is this intended? If not, I would consider a little fix to io.javalin.core.util.HttpResponseExceptionMapper in the method handleException change
if (ctx.header(Header.ACCEPT)?.contains("application/json") == true)
to something like
if (ctx.header(Header.ACCEPT)?.contains("application/json") || ctx.res.contentType.equals("application/json"))
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Jersey ignores ExceptionMapper - Stack Overflow
I made an ExceptionMapper to catch and log all exceptions, like: @Provider public class CatchAllExceptionsMapper implements ...
Read more >RESTEasy JAX-RS - JBoss.org
This exception wraps all exceptions thrown from application code. It functions much in the same way as InvocationTargetException. If there is an ExceptionMapper...
Read more >Red Hat JBoss Enterprise Application Platform 7.1
MessageBodyReaders, Writers, ContextResolvers, and ExceptionMappers. ... modify-wsdl-address is set to false this element is ignored. wsdl-port.
Read more >Release Notes - Jersey 2.0 - GitHub Pages
[JERSEY-920] - The ExceptionMapper is not handled in ... [JERSEY-1511] - MessageBodyReader does not set default content-type; [JERSEY-1513] ...
Read more >Spring Portlet MVC - Unable to return JSON data ... - GitHub
public void setDefaultContentType(MediaType defaultContentType) ... getName().contains(exceptionMapping)) { // Found it! return depth; } ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So, @Playacem thx 😃
@maxemann96 thank @Playacem, he fixed it 😃