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