(Migrated) SimpleIO exception handling

(This message has been automatically imported from the retired mailing list)

Hi,

I have a service and I am trying to handle the exception about missing
parameter which is required. I don’t know how to handle the exception. I
can’t find any documentation about it.

My service:

class MyService(Service):
class SimpleIO:
input_required = (‘name’, ‘type’)
output_required = (‘is_allowed’,)

def handle(self):
    self.response.payload.is_allowed = True

Invoke the service without type parameter:
curl localhost:17010/json/sio-example.my-service -d ‘{“name”: “foo”}’

Response:

2016-01-20 11:03:52,959 - ERROR - 4317:Dummy-256 -
zato.server.connection.http_soap.channel:22 - Caught an exception,
cid:[K0778DSNTBSHZKASR856AJAYN216], status_code:[500],
_format_exc:[Traceback (most recent call last):
File
"/opt/zato/2.0.5/zato-server/src/zato/server/connection/http_soap/channel.py",
line 198, in dispatch
payload, worker_store, self.simple_io_config, post_data)
File
"/opt/zato/2.0.5/zato-server/src/zato/server/connection/http_soap/channel.py",
line 351, in handle
params_priority=channel_item.params_pri)
File “/opt/zato/2.0.5/zato-server/src/zato/server/service/init.py”,
line 388, in update_handle
environ=kwargs.get(‘environ’))
File “/opt/zato/2.0.5/zato-server/src/zato/server/service/init.py”,
line 845, in update
service._init()
File “/opt/zato/2.0.5/zato-server/src/zato/server/service/init.py”,
line 298, in _init
self.request.init(is_sio, self.cid, self.SimpleIO, self.data_format,
self.transport, self.wsgi_environ)
File
"/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/init.py",
line 124, in init
required_list, use_channel_params_only, path_prefix, default_value,
use_text))
File
"/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/init.py",
line 162, in get_params
raise Exception(msg)
Exception: Caught an exception, param:type, params_to_visit:('name', 'type'), has_simple_io_config:True, e:Traceback (most recent call last): File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/__init__.py", line 155, in get_params self.bool_parameter_prefixes, self.int_parameters, self.int_parameter_suffixes, self.params_priority) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/sio.py", line 426, in convert_param raise ParsingException(cid, msg) ParsingException: Required input element:typenot found, value:ZATO_NOT_GIVEN, data_format:json, payload:{u’name’: u’foo’}`

Invoke using XML:

curl localhost:17010/soap/sio-example.my-service
-H “SOAPAction:sio-example.my-service” -d ‘
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/
"
xmlns:zato=“https://zato.io/ns/20130518”>
soapenv:Body
zato:request
zato:namefoo</zato:name>
</zato:request>
</soapenv:Body>
</soapenv:Envelope>’

Response:

<?xml version='1.0' encoding='UTF-8'?>

<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/
xmlns:xsi=“http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd=“http://www.w3.org/1999/XMLSchema”>
SOAP-ENV:Body
SOAP-ENV:Fault
SOAP-ENV:Client
<![CDATA[cid [K07F6KZHGZ4TB9WR7XN4B3YNAK5F], faultstring [Traceback (most recent call last): File "/opt/zato/2.0.5/zato-server/src/zato/server/connection/http_soap/channel.py", line 198, in dispatch payload, worker_store, self.simple_io_config, post_data) File "/opt/zato/2.0.5/zato-server/src/zato/server/connection/http_soap/channel.py", line 351, in handle params_priority=channel_item.params_pri) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/__init__.py", line 388, in update_handle environ=kwargs.get('environ')) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/__init__.py", line 845, in update service._init() File "/opt/zato/2.0.5/zato-server/src/zato/server/service/__init__.py", line 298, in _init self.request.init(is_sio, self.cid, self.SimpleIO, self.data_format, self.transport, self.wsgi_environ) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/__init__.py", line 124, in init required_list, use_channel_params_only, path_prefix, default_value, use_text)) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/__init__.py", line 162, in get_params raise Exception(msg) Exception: Caught an exception, param:`type`, params_to_visit:`('name', 'type')`, has_simple_io_config:`True`, e:`Traceback (most recent call last): File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/__init__.py", line 155, in get_params self.bool_parameter_prefixes, self.int_parameters, self.int_parameter_suffixes, self.params_priority) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/sio.py", line 415, in convert_param default_value, path_prefix, use_text) File "/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/sio.py", line 366, in convert_from_xml raise ParsingException(cid, msg) ParsingException: Caught an exception while parsing, payload:[<![CDATA[foo]]>],
e:[Traceback (most recent call last):
File
”/opt/zato/2.0.5/zato-server/src/zato/server/service/reqresp/sio.py”, line
362, in convert_from_xml
elem = path(’{}.{}’.format(path_prefix, param_name),
is_required).get_from(payload)
File “/opt/zato/2.0.5/zato-common/src/zato/common/init.py”, line 725,
in get_from
raise ParsingException(None, format_exc(e))
ParsingException: Traceback (most recent call last):
File “/opt/zato/2.0.5/zato-common/src/zato/common/init.py”, line 719,
in get_from
value = _ObjectPath(_path)(elem)
File “objectpath.pxi”, line 54, in lxml.objectify.ObjectPath.call
(src/lxml/lxml.objectify.c:24889)
File “objectpath.pxi”, line 218, in lxml.objectify._findObjectPath
(src/lxml/lxml.objectify.c:26972)
AttributeError: no such child: {https://zato.io/ns/20130518}type

]
`
]]]>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

On 20/01/16 12:26, Enes Ateş wrote:

I have a service and I am trying to handle the exception about missing
parameter which is required. I don’t know how to handle the exception. I
can’t find any documentation about it.

Hi there,

it’s not really possible to catch this exception but it’s not the first
time this question arises so it will make sense to add such a feature.

For now, please turn input_required into input_optional and then use
self.request.input.require_any which raises ValueError that you can catch.

For instance:

from zato.server.service import Service

class MyService(Service):

class SimpleIO:
input_optional = (‘foo’, ‘bar’, ‘baz’)

def handle(self):
self.request.input.require_any(*self.request.input)

# Or ..
self.request.input.require_any(['bar', 'baz'])

Hi,

Thank you for your solution.

Best.

On Wed, Jan 20, 2016 at 1:44 PM, Dariusz Suchojad dsuch@zato.io wrote:

On 20/01/16 12:26, Enes Ate=C5=9F wrote:

I have a service and I am trying to handle the exception about missing
parameter which is required. I don’t know how to handle the exception. =
I

can’t find any documentation about it.

Hi there,

it’s not really possible to catch this exception but it’s not the first
time this question arises so it will make sense to add such a feature.

For now, please turn input_required into input_optional and then use
self.request.input.require_any which raises ValueError that you can catch=
.

For instance:

from zato.server.service import Service

class MyService(Service):

class SimpleIO:
input_optional =3D (‘foo’, ‘bar’, ‘baz’)

def handle(self):
self.request.input.require_any(*self.request.input)

# Or ..
self.request.input.require_any(['bar', 'baz'])