pywps icon indicating copy to clipboard operation
pywps copied to clipboard

Status code 200 when error in execution handler

Open eran-pinhas opened this issue 6 years ago • 11 comments

Description

Hey,

I believe there's an issue with the status code. when the handler itself raises an error the Process.py catches it (lines below) sets the wps_request as failed (attached below) but then continues like no error occurred. As result the status code of the HTTP request is 200 and should be 500

https://github.com/geopython/pywps/blob/ec1d90f7424598a662f68c28e4de4452e2bdeaf3/pywps/app/Process.py#L232

I can think of 2 solutions:

What do you guys think? @cehbrecht @jachym

Environment

  • operating system: ubuntu 18
  • Python version: 3.6
  • PyWPS version: latest from github
  • source/distribution: git clone
  • web server: Flask

eran-pinhas avatar Dec 19 '18 13:12 eran-pinhas

@cehbrecht what do you think? I would be happy to help fixing the issue. just need your opinion on how to do it.

eran-pinhas avatar Dec 21 '18 06:12 eran-pinhas

We should use the Exceptions (HTTP status codes) according to the WPS protocol: http://www.opengeospatial.org/standards/wps

For WPS 1.0.0 see Table 62 in the spec.

Here is a list of the WPS 2.0.0 protocol: http://docs.opengeospatial.org/is/14-065/14-065.html

I'm not sure if we need to raise an exception when the process has failed. It will be reported with a status document ... and using status code=200.

The exceptions available look like to report that there is something wrong with my WPS service. But to report process failures you just use a status document.

@jachym You are more familiar with the WPS protocol.

cehbrecht avatar Dec 21 '18 09:12 cehbrecht

Execute Exceptions in WPS 2.0.0: http://docs.opengeospatial.org/is/14-065/14-065.html#61

cehbrecht avatar Dec 21 '18 10:12 cehbrecht

WPS 1.0.0:

[..] If a process fails for some reason, the implementation raises an error and places it in the exception report included in this ProcessFailed structure.

It sounds confusing to me ... but the ProcessFailed structure is part of the status report ... not part of a WPS exception.

cehbrecht avatar Dec 21 '18 10:12 cehbrecht

Hi,

this is confusing, as @cehbrecht says: ProcessFaild strucutre is part of status report - which returns 200 code.

But generally speaking, I would support more "aggressive" error handling and raise NoApplicableCode with 500 as response code.

Re-raising in Process.py sounds like less invasive solution?

jachym avatar Dec 23 '18 17:12 jachym

I agree about the ProcessFailed structure. but this is right only in the case of status request (which makes sense - the service have not failed at the status requesting).

But I find both 1&2 protocols unclear in the case of synchronous request (status=false)

eran-pinhas avatar Dec 24 '18 15:12 eran-pinhas

Re-raising in Process.py sounds like less invasive solution

Denote: the _run_process function is being called only in the sync mode (Process.py#L171) so I guess the status report is irrelevant in this discussion, isn't it?

Re-raising in Process.py sounds like less invasive solution?

I agree.

eran-pinhas avatar Dec 25 '18 07:12 eran-pinhas

@eran-pinhas ... _run_process is also called in async mode ... but it is a bit hidden: https://github.com/geopython/pywps/blob/c351a11a4149d865308217497790d1f86991d02a/pywps/processing/job.py#L20

cehbrecht avatar Jan 08 '19 16:01 cehbrecht

Adding an example with returning status code 200 and status report containing an exception report:

<?xml version="1.0" encoding="UTF-8"?>
<wps:ExecuteResponse xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 ../wpsExecute_response.xsd"
  service="WPS" version="1.0.0" xml:lang="en-US" serviceInstance="http://localhost:5000/wps?request=GetCapabilities&amp;amp;service=WPS" statusLocation="">
  <wps:Process wps:processVersion="1.5">
    <ows:Identifier>hello</ows:Identifier>
    <ows:Title>Say Hello</ows:Title>
    <ows:Abstract>Just says a friendly Hello. Returns a literal string output with Hello plus the inputed name.</ows:Abstract>
  </wps:Process>
  <wps:Status creationTime="2019-01-08T18:23:27Z">
    <wps:ProcessFailed>
      <wps:ExceptionReport>
        <ows:Exception exceptionCode="NoApplicableCode" locator="None">
          <ows:ExceptionText>Process failed, please check server error log</ows:ExceptionText>
        </ows:Exception>
      </wps:ExceptionReport>
    </wps:ProcessFailed>
  </wps:Status>
</wps:ExecuteResponse>

cehbrecht avatar Jan 08 '19 17:01 cehbrecht

... and here is the response using PR #446:

<?xml version="1.0" encoding="UTF-8"?>
<!-- PyWPS 4.3.dev0 -->
<ows:ExceptionReport xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/ows/1.1 http://schemas.opengis.net/ows/1.1.0/owsExceptionReport.xsd" version="1.0.0">
  <ows:Exception exceptionCode="NoApplicableCode" locator="">
    <ows:ExceptionText>Process failed, please check server error log</ows:ExceptionText>
  </ows:Exception>
</ows:ExceptionReport>

In both cases we get the info there is something wrong but the unpatched version provides more details (status, process identifier, ...).

cehbrecht avatar Jan 08 '19 17:01 cehbrecht

Hello,

For the WPS 1.0.0 state section 10.3.1 :

In the most primitive case, when a response form of RawDataOutput‖ is requested [...] In all other cases, the response to a valid Execute operation request is an ExecuteResponse XML document.

As far I understand is that if the request is valid, the response status is 200 in WPS 1.0.0. In WPS 2.0.0 it's seems different.

Best regards

gschwind avatar Feb 11 '22 14:02 gschwind