mirror of
https://github.com/BililiveRecorder/BililiveRecorder.git
synced 2024-11-15 19:22:19 +08:00
parent
abe335b829
commit
6514bcf9c1
|
@ -5,7 +5,17 @@ namespace BililiveRecorder.Core.Api
|
|||
{
|
||||
internal class BilibiliApiResponseCodeNotZeroException : Exception
|
||||
{
|
||||
public int? Code { get; }
|
||||
public string? Body { get; }
|
||||
|
||||
public BilibiliApiResponseCodeNotZeroException(int? code, string? body) : base(message: "BiliBili API Code: " + (code?.ToString() ?? "(null)") + "\n" + body)
|
||||
{
|
||||
this.Code = code;
|
||||
this.Body = body;
|
||||
}
|
||||
|
||||
public BilibiliApiResponseCodeNotZeroException() { }
|
||||
[Obsolete]
|
||||
public BilibiliApiResponseCodeNotZeroException(string message) : base(message) { }
|
||||
public BilibiliApiResponseCodeNotZeroException(string message, Exception innerException) : base(message, innerException) { }
|
||||
protected BilibiliApiResponseCodeNotZeroException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
|
|
|
@ -71,7 +71,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
|
||||
private void Config_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(this.config.Cookie) || e.PropertyName == nameof(this.config.TimingApiTimeout))
|
||||
if (e.PropertyName is (nameof(this.config.Cookie)) or (nameof(this.config.TimingApiTimeout)))
|
||||
this.UpdateHttpClient();
|
||||
}
|
||||
|
||||
|
@ -89,9 +89,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
var text = await resp.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||
|
||||
var obj = JsonConvert.DeserializeObject<BilibiliApiResponse<T>>(text);
|
||||
if (obj?.Code != 0)
|
||||
throw new BilibiliApiResponseCodeNotZeroException("Bilibili api code: " + (obj?.Code?.ToString() ?? "(null)") + "\n" + text);
|
||||
return obj;
|
||||
return obj?.Code != 0 ? throw new BilibiliApiResponseCodeNotZeroException(obj?.Code, text) : obj;
|
||||
}
|
||||
|
||||
public async Task<BilibiliApiResponse<RoomInfo>> GetRoomInfoAsync(int roomid)
|
||||
|
@ -118,7 +116,7 @@ namespace BililiveRecorder.Core.Api.Http
|
|||
|
||||
var obj = jobject.ToObject<BilibiliApiResponse<RoomInfo>>();
|
||||
if (obj?.Code != 0)
|
||||
throw new BilibiliApiResponseCodeNotZeroException("Bilibili api code: " + (obj?.Code?.ToString() ?? "(null)") + "\n" + text);
|
||||
throw new BilibiliApiResponseCodeNotZeroException(obj?.Code, text);
|
||||
|
||||
obj.Data!.RawBilibiliApiJsonData = jobject["data"] as JObject;
|
||||
|
||||
|
|
|
@ -38,7 +38,12 @@ namespace BililiveRecorder.Core
|
|||
this.RequestFailedCircuitBreakerPolicy = Policy
|
||||
.Handle<HttpRequestException>()
|
||||
.Or<JsonException>()
|
||||
.Or<BilibiliApiResponseCodeNotZeroException>()
|
||||
.Or<BilibiliApiResponseCodeNotZeroException>(x =>
|
||||
{
|
||||
return x.Code is not 19002005 // 19002005: 房间已加密
|
||||
and not 19002000 // 19002000: 房间不存在(获取初始化数据失败)
|
||||
;
|
||||
})
|
||||
.AdvancedCircuitBreakerAsync(
|
||||
failureThreshold: 0.8,
|
||||
samplingDuration: TimeSpan.FromSeconds(30),
|
||||
|
|
|
@ -271,6 +271,12 @@ namespace BililiveRecorder.Core
|
|||
this.logger.Warning("因为硬盘空间已满,本次不再自动重试启动录制。");
|
||||
return;
|
||||
}
|
||||
else if (ex is BilibiliApiResponseCodeNotZeroException notzero && notzero.Code == 19002005)
|
||||
{
|
||||
// 房间已加密
|
||||
this.logger.Warning("房间已加密,无密码获取不到直播流,本次不再自动重试启动录制。");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 请求直播流出错时的重试逻辑
|
||||
|
|
Loading…
Reference in New Issue
Block a user