Custom error handling scripts that consider the request file extension?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom error handling scripts that consider the request file extension?

Eric Norman
Does anyone have a convenient existing solution for error handling that
considers the incoming request file extension when resolving which script
to use to render the error response?

For example, I am expecting that a request to
http://localhost:8080/bogus.json should return a JSON response with the 404
error details in JSON when the resource doesn't exist.  (also similar
behavior should be possible for a .txt or .xml file extension)

What I see currently is that SlingServletResolver#handleError ignores the
incoming file extension and always returns the error page as html.

I would expect that an "errorhandler" script/servlet registered with
("sling.servlet.resourceTypes=sling/servlet/errorhandler",
"sling.servlet.extensions=json", "sling.servlet.methods=404") should be
preferred when the incoming request has a .json extension, and then use the
original html error response as a fallback for all other scenarios.

Basically I would like to have the client get JSON back when something goes
wrong instead of html that won't parse as JSON.

If no one disagrees, I can open a bug report and provide the proposed
changes to org.apache.sling.servlets.resolver

Regards,
Eric
Reply | Threaded
Open this post in threaded view
|

Re: Custom error handling scripts that consider the request file extension?

Bertrand Delacretaz
Hi,

On Thu, Aug 9, 2018 at 10:01 PM Eric Norman <[hidden email]> wrote:
> ...Basically I would like to have the client get JSON back when something goes
> wrong instead of html that won't parse as JSON.
>
> If no one disagrees, I can open a bug report and provide the proposed
> changes to org.apache.sling.servlets.resolver...

That sounds reasonable, as long as changes to that core module are
covered by strong tests.

-Bertrand