Skip to content

Commit

Permalink
Merge pull request #252 from onerain88/fix/handle-rtm-hook
Browse files Browse the repository at this point in the history
处理 RTM hook
  • Loading branch information
onerain88 authored Jul 3, 2023
2 parents fd6ea5f + bf4980f commit 3590b86
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Realtime/Realtime.AOT/Realtime.AOT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@
<Compile Include="..\Realtime\Internal\Connection\LCRTMHeartBeat.cs">
<Link>Realtime\Internal\Connection\LCRTMHeartBeat.cs</Link>
</Compile>
<Compile Include="..\Realtime\Public\LCIMException.cs">
<Link>Realtime\LCIMException.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\link.xml">
Expand Down
6 changes: 4 additions & 2 deletions Realtime/Realtime/Internal/Connection/LCConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ internal async Task<LCIMMessage> 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;
}

Expand Down
14 changes: 14 additions & 0 deletions Realtime/Realtime/Public/LCIMException.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 3590b86

Please sign in to comment.