Javalin: ExceptionMapper ignores defaultContentType

Created on 22 Oct 2018  路  5Comments  路  Source: tipsy/javalin

Consider 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"))

BUG

Most helpful comment

So, @Playacem thx :)

All 5 comments

Thanks for the issue. I'm currently traveling, but I'll have a look when I get back.

@maxemann96 thanks, looks like you've found a bug. Would you like to submit a PR to fix it?

Oh, ok this was very quick, thx for your time :)

@maxemann96 thank @Playacem, he fixed it :)

So, @Playacem thx :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bvicenzo picture bvicenzo  路  3Comments

jonerer picture jonerer  路  4Comments

azurvii picture azurvii  路  5Comments

tipsy picture tipsy  路  4Comments

gane5h picture gane5h  路  3Comments