-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDebugMetricsWebRequestController.cs
More file actions
41 lines (36 loc) · 1.87 KB
/
Copy pathDebugMetricsWebRequestController.cs
File metadata and controls
41 lines (36 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using Cysharp.Threading.Tasks;
using DCL.DebugUtilities.UIBindings;
using DCL.WebRequests.RequestsHub;
namespace DCL.WebRequests
{
public class DebugMetricsWebRequestController : IWebRequestController
{
private readonly IWebRequestController origin;
private readonly ElementBinding<ulong> requestCannotConnectDebugMetric;
private readonly ElementBinding<ulong> requestCompleteDebugMetric;
public DebugMetricsWebRequestController(IWebRequestController origin,
ElementBinding<ulong> requestCannotConnectDebugMetric, ElementBinding<ulong> requestCompleteDebugMetric)
{
this.origin = origin;
this.requestCannotConnectDebugMetric = requestCannotConnectDebugMetric;
this.requestCompleteDebugMetric = requestCompleteDebugMetric;
}
public async UniTask<TResult?> SendAsync<TWebRequest, TWebRequestArgs, TWebRequestOp, TResult>(
RequestEnvelope<TWebRequest, TWebRequestArgs> envelope, TWebRequestOp op, IStreamableLoadingProgressHandler? progressHandler = null)
where TWebRequest: struct, ITypedWebRequest
where TWebRequestArgs: struct
where TWebRequestOp: IWebRequestOp<TWebRequest, TResult>
{
try { return await origin.SendAsync<TWebRequest, TWebRequestArgs, TWebRequestOp, TResult>(envelope, op, progressHandler); }
catch (Exception e) when (e is not OperationCanceledException)
{
if (e.Message.Contains(WebRequestUtils.CANNOT_CONNECT_ERROR))
requestCannotConnectDebugMetric.Value++;
throw; // don't re-throw it as a new exception as we loose the original type in that case
}
finally { requestCompleteDebugMetric.Value++; }
}
IRequestHub IWebRequestController.RequestHub => origin.RequestHub;
}
}