Skip to content

feat: use custom error servlet to return json rather than default html#281

Open
rithvik-doshi wants to merge 16 commits into
devfrom
json-error-servlet
Open

feat: use custom error servlet to return json rather than default html#281
rithvik-doshi wants to merge 16 commits into
devfrom
json-error-servlet

Conversation

@rithvik-doshi
Copy link
Copy Markdown
Contributor

@rithvik-doshi rithvik-doshi commented Mar 19, 2026

Change the response on server-side errors to return JSON instead of the default Tomcat HTML, plus other error html pages we have defined. This allows the frontend to parse the response cleanly and program behavior based on error codes and messages.

To test - induce any of the following kinds of errors and note the response has changed to valid json: 400, 401, 403, 404, 500, any Throwable from Monolith.

@rithvik-doshi rithvik-doshi marked this pull request as ready for review March 31, 2026 13:51
@rithvik-doshi rithvik-doshi requested a review from a team as a code owner March 31, 2026 13:51
Copy link
Copy Markdown
Contributor

@tevanburen tevanburen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally: it returns json instead of html, which is better for FE to parse

@rithvik-doshi rithvik-doshi marked this pull request as draft March 31, 2026 17:38
Comment thread WebContent/WEB-INF/web.xml Outdated
<location>/error/json</location>
</error-page>
<error-page>
<error-code>401</error-code>
Copy link
Copy Markdown
Contributor

@agmontem-devel agmontem-devel Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example where we generate a 401 tomcat default html page? I see examples for all the others

@agmontem-devel
Copy link
Copy Markdown
Contributor

agmontem-devel commented Apr 1, 2026

The comment from Thomas makes me question the scenarios that motivated this change. There are still scenarios where errors yield html, but just not the default tomcat error page mappings we had. Is that ok? Was the desired change supposed to change other html error page responses?

For example:
Calling /Monolith/public_home/{uuid}/portals/blah will yield a 404 html response built in PublicHomeCheckFilter
Calling /Monolith/api/notthere gives a 0 content length 404

@tevanburen
Copy link
Copy Markdown
Contributor

The js sdk is ok with receiving html from the BE (as in, it won't cause problems), it just isn't able to parse it. For that reason, json is preferred. I think we should attempt to send json wherever we can - If Anthony found a few places where we can also update to json, that's great. But it's also not a problem if we aren't able to be thorough. I'll take as much json as can be given, and any html leftover will still be ok

@rithvik-doshi rithvik-doshi marked this pull request as ready for review April 3, 2026 16:02
@rithvik-doshi rithvik-doshi marked this pull request as draft April 3, 2026 16:02
@rithvik-doshi rithvik-doshi marked this pull request as ready for review April 8, 2026 14:36
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 this pull request may close these issues.

3 participants