You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Eric Norman <er...@gmail.com> on 2018/08/09 20:01:31 UTC

Custom error handling scripts that consider the request file extension?

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

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

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Thu, Aug 9, 2018 at 10:01 PM Eric Norman <er...@gmail.com> 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