Catch HttpRequestException in LibraryConnector
This commit is contained in:
parent
49ab8928b1
commit
92bc3d5aa8
@ -41,16 +41,34 @@ public abstract class LibraryConnector : GlobalBase
|
|||||||
Method = HttpMethod.Get,
|
Method = HttpMethod.Get,
|
||||||
RequestUri = new Uri(url)
|
RequestUri = new Uri(url)
|
||||||
};
|
};
|
||||||
HttpResponseMessage response = client.Send(requestMessage);
|
try
|
||||||
logger?.WriteLine("LibraryManager.NetClient", $"GET {url} -> {(int)response.StatusCode}: {response.ReasonPhrase}");
|
{
|
||||||
|
|
||||||
if(response.StatusCode is HttpStatusCode.Unauthorized && response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
|
logger?.WriteLine("LibraryManager.NetClient",
|
||||||
|
$"GET {url} -> {(int)response.StatusCode}: {response.ReasonPhrase}");
|
||||||
|
|
||||||
|
if (response.StatusCode is HttpStatusCode.Unauthorized &&
|
||||||
|
response.RequestMessage!.RequestUri!.AbsoluteUri != url)
|
||||||
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
return MakeRequest(response.RequestMessage!.RequestUri!.AbsoluteUri, authScheme, auth, logger);
|
||||||
else if (response.IsSuccessStatusCode)
|
else if (response.IsSuccessStatusCode)
|
||||||
return response.Content.ReadAsStream();
|
return response.Content.ReadAsStream();
|
||||||
else
|
else
|
||||||
return Stream.Null;
|
return Stream.Null;
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
switch (e)
|
||||||
|
{
|
||||||
|
case HttpRequestException:
|
||||||
|
logger?.WriteLine("LibraryManager.NetClient", $"Failed to make Request:\n\r{e}");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
return Stream.Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static bool MakePost(string url, string authScheme, string auth, Logger? logger)
|
public static bool MakePost(string url, string authScheme, string auth, Logger? logger)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user