From fd2d05856efe507306683d522363eebe4f69d02c Mon Sep 17 00:00:00 2001 From: Muzzammil Shahid Date: Fri, 26 Jul 2024 18:24:28 +0500 Subject: [PATCH] Handle error of invocation function --- lib/src/session.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/src/session.dart b/lib/src/session.dart index 7f31a4d..a771eaa 100644 --- a/lib/src/session.dart +++ b/lib/src/session.dart @@ -62,10 +62,18 @@ class Session { } else if (message is msg.Invocation) { var endpoint = _registrations[message.registrationID]; if (endpoint != null) { - Result result = endpoint(Invocation(args: message.args, kwargs: message.kwargs, details: message.details)); - Object data = _wampSession.sendMessage( - msg.Yield(message.requestID, args: result.args, kwargs: result.kwargs, options: result.details), - ); + msg.Message msgToSend; + try { + var result = endpoint(Invocation(args: message.args, kwargs: message.kwargs, details: message.details)); + msgToSend = msg.Yield(message.requestID, args: result.args, kwargs: result.kwargs, options: result.details); + } on ApplicationError catch (e) { + msgToSend = msg.Error(message.messageType(), message.requestID, e.message, args: e.args, kwargs: e.kwargs); + } on Exception catch (e) { + msgToSend = + msg.Error(message.messageType(), message.requestID, "wamp.error.runtime_error", args: [e.toString()]); + } + + Object data = _wampSession.sendMessage(msgToSend); _baseSession.send(data); } } else if (message is msg.Unregistered) {