Hi David,
Am 01.04.2016 um 11:25 schrieb
da...@spinshell.com:
> Hi,
>
> Is there any guidance on how exceptions should be used in a WAMP
> application?
Sadly, not.
>
> What I've been able to piece together so far:
>
> - all application level exceptions should derive from
> autobahn.wamp.exception.ApplicationError
Correct.
> - all ApplicationErrors should have a defined URI for the type of error,
> like com.example.error.foo
Yep.
> - the autobahn.wamp.uri.error decorator seems to do... nothing?!
Nope;)
It does something. Eg
https://github.com/crossbario/autobahn-python/blob/master/examples/twisted/wamp/rpc/errors/frontend.py
Given a custom exception:
@wamp.error(u"com.myapp.error1")
class AppError1(Exception):
you can do
self.define(AppError1)
on your WAMP session, and the do
try:
yield self.call(u'com.myapp.compare', 3, 17)
except AppError1 as e:
print("Compare Error: {}".format(e))
That is, Autobahn will auto-map the incoming error not to a general
ApplicationError (as is the default behavior), but directly to your
custom error class.
Please let me know if that helps / makes sense,
Cheers,
/Tobias
>
> In particular I'm rather confused about that last point; I can't seem to
> see any point in using that decorator.
>
> Would I be correct in simply defining a bunch of possible errors like so:
>
> |
> classFooError(ApplicationError):
> def__init__(self,*args,**kwargs):
> super().__init__('com.example.error.foo',*args,**kwargs)
> |
>
> And raise them in any method:
>
> |
> @register('com.example.bar')
> defbar(self):
> raiseFooError
> |
>
> Best,
> David
>
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
autobahnws+...@googlegroups.com
> <mailto:
autobahnws+...@googlegroups.com>.
> To post to this group, send email to
autob...@googlegroups.com
> <mailto:
autob...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/autobahnws/d5846d9d-ccc2-4e02-971d-78e9f8188caf%40googlegroups.com
> <
https://groups.google.com/d/msgid/autobahnws/d5846d9d-ccc2-4e02-971d-78e9f8188caf%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit
https://groups.google.com/d/optout.