Added HttpException so we can actually catch server errors again!
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>19793545-ef89-48f4-8100-3ebaad0a9141</ProjectGuid>
|
||||
<RootNamespace>Discord.Net.Commands</RootNamespace>
|
||||
<RootNamespace>Discord</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -88,6 +88,9 @@
|
||||
<Compile Include="..\Discord.Net\Helpers\Http.cs">
|
||||
<Link>Helpers\Http.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net\Helpers\HttpException.cs">
|
||||
<Link>Helpers\HttpException.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\Discord.Net\Invite.cs">
|
||||
<Link>Invite.cs</Link>
|
||||
</Compile>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>acfb060b-ec8a-4926-b293-04c01e17ee23</ProjectGuid>
|
||||
<RootNamespace>Discord.Net</RootNamespace>
|
||||
<RootNamespace>Discord</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
@@ -596,7 +596,7 @@ namespace Discord
|
||||
{
|
||||
await DiscordAPI.LeaveServer(serverId);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) {}
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) {}
|
||||
return _servers.Remove(serverId);
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ namespace Discord
|
||||
{
|
||||
var response = await DiscordAPI.DestroyChannel(channelId);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
return _channels.Remove(channelId);
|
||||
}
|
||||
|
||||
@@ -655,7 +655,7 @@ namespace Discord
|
||||
{
|
||||
await DiscordAPI.Unban(serverId, userId);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
//Invites
|
||||
@@ -718,7 +718,7 @@ namespace Discord
|
||||
var response = await DiscordAPI.GetInvite(id);
|
||||
await DiscordAPI.DeleteInvite(response.Code);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
}
|
||||
|
||||
//Chat
|
||||
@@ -781,8 +781,8 @@ namespace Discord
|
||||
await DiscordAPI.DeleteMessage(channelId, msgId);
|
||||
return _messages.Remove(msgId);
|
||||
}
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.NotFound) { }
|
||||
catch (WebException ex) when ((ex.Response as HttpWebResponse)?.StatusCode == HttpStatusCode.InternalServerError) { } //TODO: Remove me - temporary fix for deleting nonexisting messages
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
|
||||
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.InternalServerError) { } //TODO: Remove me - temporary fix for deleting nonexisting messages
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -134,14 +134,14 @@ namespace Discord.Helpers
|
||||
{
|
||||
response = await _client.SendAsync(msg, HttpCompletionOption.ResponseContentRead);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"The server responded with error {(int)response.StatusCode}.");
|
||||
throw new HttpException(response.StatusCode);
|
||||
result = await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await _client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new InvalidOperationException($"The server responded with error {(int)response.StatusCode}.");
|
||||
throw new HttpException(response.StatusCode);
|
||||
result = null;
|
||||
}
|
||||
|
||||
|
||||
16
src/Discord.Net/Helpers/HttpException.cs
Normal file
16
src/Discord.Net/Helpers/HttpException.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
|
||||
namespace Discord.Helpers
|
||||
{
|
||||
public class HttpException : Exception
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; }
|
||||
|
||||
public HttpException(HttpStatusCode statusCode)
|
||||
: base($"The server responded with error {statusCode}")
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,20 @@
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "7.0.1",
|
||||
"Microsoft.Net.Http": "2.2.22"
|
||||
"Newtonsoft.Json": "7.0.1"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"net45": { },
|
||||
"dnx451": { },
|
||||
"net45": {
|
||||
"dependencies": {
|
||||
"Microsoft.Net.Http": "2.2.22"
|
||||
}
|
||||
},
|
||||
"dnx451": {
|
||||
"dependencies": {
|
||||
"Microsoft.Net.Http": "2.2.22"
|
||||
}
|
||||
},
|
||||
"dnxcore50": {
|
||||
"dependencies": {
|
||||
"System.Collections.Concurrent": "4.0.10",
|
||||
@@ -33,4 +40,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user