From bf4980f287c55b61ae4f715d36961d0f3e2425bd Mon Sep 17 00:00:00 2001 From: leancloud-bot Date: Mon, 3 Jul 2023 16:33:51 +0800 Subject: [PATCH] fix: handle rtm hook --- Realtime/Realtime.AOT/Realtime.AOT.csproj | 3 +++ .../Realtime/Internal/Connection/LCConnection.cs | 6 ++++-- .../Internal/Controller/LCIMMessageController.cs | 5 +++++ Realtime/Realtime/Public/LCIMException.cs | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 Realtime/Realtime/Public/LCIMException.cs diff --git a/Realtime/Realtime.AOT/Realtime.AOT.csproj b/Realtime/Realtime.AOT/Realtime.AOT.csproj index 672dc362..ed376e6b 100644 --- a/Realtime/Realtime.AOT/Realtime.AOT.csproj +++ b/Realtime/Realtime.AOT/Realtime.AOT.csproj @@ -124,6 +124,9 @@ Realtime\Internal\Connection\LCRTMHeartBeat.cs + + Realtime\LCIMException.cs + diff --git a/Realtime/Realtime/Internal/Connection/LCConnection.cs b/Realtime/Realtime/Internal/Connection/LCConnection.cs index 5595c47e..c486ce4f 100644 --- a/Realtime/Realtime/Internal/Connection/LCConnection.cs +++ b/Realtime/Realtime/Internal/Connection/LCConnection.cs @@ -179,9 +179,11 @@ private void OnMessage(byte[] bytes, int length) { // 错误 ErrorCommand error = command.ErrorMessage; int code = error.Code; - string detail = error.Detail; + string reason = error.Reason; + int appCode = error.AppCode; + string appMsg = error.AppMsg; // 包装成异常抛出 - LCException exception = new LCException(code, detail); + LCIMException exception = new LCIMException(code, reason, appCode, appMsg); tcs.TrySetException(exception); } else { tcs.TrySetResult(command); diff --git a/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs b/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs index 59dcea5a..08cbcc6c 100644 --- a/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs +++ b/Realtime/Realtime/Internal/Controller/LCIMMessageController.cs @@ -66,6 +66,11 @@ internal async Task Send(string convId, message.Id = ack.Uid; message.SentTimestamp = ack.T; message.FromClientId = Client.Id; + + if (ack.HasCode) { + throw new LCIMException(ack.Code, ack.Reason, ack.AppCode, ack.AppMsg); + } + return message; } diff --git a/Realtime/Realtime/Public/LCIMException.cs b/Realtime/Realtime/Public/LCIMException.cs new file mode 100644 index 00000000..6dbc17cd --- /dev/null +++ b/Realtime/Realtime/Public/LCIMException.cs @@ -0,0 +1,14 @@ + +namespace LeanCloud.Realtime { + public class LCIMException : LCException { + public int AppCode { get; private set; } + + public string AppMessage { get; private set; } + + public LCIMException(int code, string message, int appCode, string appMessage) : + base(code, message) { + AppCode = appCode; + AppMessage = appMessage; + } + } +}