Skip to content

Commit ccf461b

Browse files
authored
[Core] Add specific exception for Stranger not found (#52)
1 parent 75b8216 commit ccf461b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Lagrange.Core/Internal/Services/System/FetchStrangerService.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ protected override ValueTask<FetchStrangerEventResp> Parse(ReadOnlyMemory<byte>
9191
property => property.Value
9292
);
9393

94+
// Check exists
95+
if (!bytes.TryGetValue(20002, out byte[]? nicknameBytes))
96+
{
97+
throw new OperationException(-1, "Stranger not found");
98+
}
99+
94100
// Birthday
95101
byte[] birthday = bytes[20031];
96102
int year = BinaryPrimitives.ReadUInt16BigEndian(birthday.AsSpan(0, 2));
@@ -99,7 +105,7 @@ protected override ValueTask<FetchStrangerEventResp> Parse(ReadOnlyMemory<byte>
99105

100106
return ValueTask.FromResult(new FetchStrangerEventResp(new BotStranger(
101107
response.Body.Uin,
102-
Encoding.UTF8.GetString(bytes[20002]),
108+
Encoding.UTF8.GetString(nicknameBytes),
103109
string.Empty, // Can't not get uid
104110
Encoding.UTF8.GetString(bytes[102]),
105111
Encoding.UTF8.GetString(bytes[103]),

0 commit comments

Comments
 (0)