[MarkLogic Dev General] Error handler not kicked off

John Snelson john.snelson at marklogic.com
Fri Aug 10 08:13:02 PDT 2012

Hi Florent,

The error handler is only invoked if the query terminates by raising an 
(XQuery) error. Otherwise the result of the query is returned, even if 
the HTTP response code is classified as an error response.


On 10/08/12 16:08, Florent Georges wrote:
>    Hi,
>    The current Application Developer’s Guide (labeled MarkLogic 5 -
> October, 2011) says in §17.1.1 "Overview of Custom HTTP Error Pages":
>      When any 400 or 500 HTTP exception is thrown (except for a 503
>      error), an XQuery module is evaluated and the results are returned
>      to the client.
>    By "throwing any 400 or 500 HTTP exception", I thought it meant
> "setting the HTTP response code, using xdmp:set-response-code(), to
> any 400 or 500 error code".  But it seems I'm wrong.  I have the
> following error handler, configured in the field "error handler" in my
> HTTP app server:
>      xquery version "1.0-ml";
>      <error>HTTP error: { xdmp:get-response-code() }</error>
> and a sample page returning a 404:
>      xquery version "1.0-ml";
>      xdmp:set-response-code(404, "Not found") ,
>      <page>Should NOT be returned.</page>
>    When I try to GET it through HTTP, it is actually returned.  If
> I change xdmp:set-response-code() to fn:error(), I get the expected
> result: "<error>HTTP error: 500 Internal Server Error</error>".
>    Why the error handler is not kicked off in the first case?  Did
> I miss anything?
>    Regards,

John Snelson, Lead Engineer                    http://twitter.com/jpcs
MarkLogic Corporation                         http://www.marklogic.com

More information about the General mailing list