Re: [Saxon-JS 2] Handling non-XML error responses

Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]> Wed, 18 Nov 2020 15:53:22 +0000
Newsgroups gmane.text.xml.saxon.help
Message-ID <[email protected]>
I've created issue 4830 for this:

https://saxonica.plan.io/issues/4830

Michael Kay
Saxonica

> On 2 Nov 2020, at 20:59, Martynas Jusevičius <martynas-tyFqBaoSXPC1Z/[email protected]> wrote:
> 
> Hi,
> 
> how do I handle 4xx error responses in a <ixsl:schedule-action
> http-request> callback template when the response body is not HTML?
> 
> The pattern I'm using:
> 
>    <xsl:template name="onResponseLoad">
>        <xsl:context-item as="map(*)" use="required"/>
> 
>        <xsl:variable name="response" select="." as="map(*)"/>
>        <xsl:choose>
>            <xsl:when test="?status = 200 and ?media-type =
> ('application/rdf+xml', 'application/sparql-results+xml')">
>                <xsl:for-each select="?body">
>                    <!-- do something with the XML body -->
>                </xsl:for-each>
>            </xsl:when>
>            <xsl:otherwise>
>                <!-- handle error, show $response?message -->
>            </xsl:otherwise>
>        </xsl:choose>
>    </xsl:template>
> 
> When the error response contains an HTML body, the execution never
> gets to the <xsl:otherwise> as I get an error:
> 
> code: "FODC0002"
> message: "Misplaced or malformed XML: This page contains the following
> errors:error on line 1 at column 2: StartTag: invalid element
> name↵Below is a rendering of the page up to the first error."
> name: "XError"
> stack: "Error↵ at new q
> (https://localhost:4443/static/com/atomgraph/linkeddatahub/js/saxon-js/SaxonJS2.rt.js:137:273)↵
> at parseXmlFromString
> (https://localhost:4443/static/com/atomgraph/linkeddatahub/js/saxon-js/SaxonJS2.rt.js:684:475)↵
> at XMLHttpRequest.w.onload
> (https://localhost:4443/static/com/atomgraph/linkeddatahub/js/saxon-js/SaxonJS2.rt.js:683:79)"
> 
> The responses with content type "text/html" are served by Tomcat and
> look like this:
> 
> <!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad
> Request</title><style type="text/css">body
> {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b
> {color:white;background-color:#525D76;} h1 {font-size:22px;} h2
> {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a
> {color:black;} .line
> {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP
> Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Status
> Report</p><p><b>Message</b> Bad Request</p><p><b>Description</b> The
> server cannot or will not process the request due to something that is
> perceived to be a client error (e.g., malformed request syntax,
> invalid request message framing, or deceptive request routing).</p><hr
> class="line" /><h3>Apache Tomcat/9.0.31</h3></body></html>
> 
> I'm wondering at which point is Saxon-JS attempting to parse XML from
> the response body and why does it attempt that if the content type is
> not XML?
> 
> 
> Martynas
> 
> 
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help