(Migrated) Is it possible to catch SIO Exceptions

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

If I have the following SIO definition:

class SimpleIO:
    input_required = (’test_arg',)
    output_required = ('status',)

Is it possible to catch the ZatoException in my service when no input is received?

I’m trying the following with no success

def handle(self):
try:
e = self.request.input.test_arg
except ZatoException as e:
self.response.status_code = httplib.BAD_REQUEST
self.response.payload.status = e.message

On 21/08/15 18:46, Ivan Villareal wrote:

Is it possible to catch the ZatoException in my service when no input is received?

Hi Ivan,

the validation takes place before your handle method gets called so it’s
not possible to catch this exception.

If you open a ticket on GH it will make sense to add an
on_input_validation_error-like method that would get called in such
situations.

Note that you can use .require_any - a shortcut to make sure that at
least one of the elements the function receives was provided on input.

It will raise ValueError if they aren’t which you can catch and turn
into an HTTP status code as needed.

from zato.server.service import Service

class MyService(Service):
class SimpleIO:
input_optional = (‘a’, ‘b’, ‘c’)

def handle(self):
    self.request.input.require_any('a', 'b')