babalae/better-genshin-impact · error · NotifierException
Error sending ServerChan message: {ex.Message}
Error message
Error sending ServerChan message: {ex.Message} What it means
Catch-all wrapper: any non-NotifierException inside SendAsync's try is re-wrapped. Importantly, this is also what surfaces the ArgumentException thrown by GetServerChanApiUrl for a malformed sctp key (error 531), because GetServerChanApiUrl is called inside the try at line 39 and the generic catch at line 65 swallows ArgumentException into this message.
Source
Thrown at BetterGenshinImpact/Service/Notifier/ServerChanNotifier.cs:67
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
request.Content = new StringContent(postData, Encoding.UTF8, "application/x-www-form-urlencoded");
// 发送请求
var response = await _httpClient.SendAsync(request);
// 检查响应状态
if (!response.IsSuccessStatusCode)
{
throw new NotifierException($"ServerChan调用失败,状态码: {response.StatusCode}");
}
}
catch (NotifierException)
{
throw;
}
catch (System.Exception ex)
{
throw new NotifierException($"Error sending ServerChan message: {ex.Message}");
}
}
/// <summary>
/// 根据sendKey格式获取正确的API URL
/// </summary>
private string GetServerChanApiUrl(string key)
{
// 判断sendkey是否以"sctp"开头并提取数字部分
if (key.StartsWith("sctp"))
{
var match = Regex.Match(key, @"^sctp(\d+)t");
if (match.Success)
{
var num = match.Groups[1].Value;
return $"https://{num}.push.ft07.com/send/{key}.send";
}
elseView on GitHub (pinned to a7cb36712d)
Solutions
- Move GetServerChanApiUrl validation OUTSIDE the try (or validate key format at construction) so error 531 surfaces cleanly.
- Preserve the inner exception.
- Differentiate network (HttpRequestException) from argument (ArgumentException) catches.
Example fix
// before
try
{
string apiUrl = GetServerChanApiUrl(_sendKey);
...
}
catch (NotifierException) { throw; }
catch (System.Exception ex)
{
throw new NotifierException($"Error sending ServerChan message: {ex.Message}");
}
// after — validate key format up front so ArgumentException is not swallowed
string apiUrl = GetServerChanApiUrl(_sendKey); // throws ArgumentException cleanly if malformed
try
{
...
}
catch (NotifierException) { throw; }
catch (HttpRequestException ex)
{
throw new NotifierException($"ServerChan network error: {ex.Message}", ex);
}
catch (System.Exception ex)
{
throw new NotifierException($"Error sending ServerChan message: {ex.Message}", ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Validate key format up front so ArgumentException is not swallowed by the generic catch.
if (sendKey.StartsWith("sctp") && !Regex.IsMatch(sendKey, @"^sctp\d+t"))
throw new InvalidOperationException("sctp SendKey format is invalid."); Try / catch
try { await serverChanNotifier.SendAsync(data); }
catch (NotifierException ex) when (ex.Message.StartsWith("Error sending ServerChan"))
{ /* could be network OR a malformed key swallowed — re-check key format separately */ } Prevention
- Move GetServerChanApiUrl out of the try-block so format errors surface clearly.
- Separate HttpRequestException (network) from ArgumentException (config).
- Preserve the inner exception.
When it happens
Trigger: HttpRequestException (DNS/socket); JsonException; OR ArgumentException from a bad sctp key format (error 531 propagates as this 530 message, losing the specific 'Invalid key format' text).
Common situations: Network outage; the sctp SendKey is malformed so the user sees a generic 'Error sending ServerChan message' instead of the helpful format hint.
Related errors
- Error sending MeoW message: {ex.Message}
- Error sending OneBot message: {ex.Message}
- ServerChan SendKey为空
- ServerChan调用失败,状态码: {response.StatusCode}
- Invalid key format for sctp.
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/9d4ea114c23ed919.
Report an issue: GitHub.