| @@ -7,7 +7,7 @@ | |||||
| <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||||
| <PropertyGroup Label="Globals"> | <PropertyGroup Label="Globals"> | ||||
| <ProjectGuid>19793545-ef89-48f4-8100-3ebaad0a9141</ProjectGuid> | <ProjectGuid>19793545-ef89-48f4-8100-3ebaad0a9141</ProjectGuid> | ||||
| <RootNamespace>Discord.Net.Commands</RootNamespace> | |||||
| <RootNamespace>Discord</RootNamespace> | |||||
| <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||||
| <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| @@ -88,6 +88,9 @@ | |||||
| <Compile Include="..\Discord.Net\Helpers\Http.cs"> | <Compile Include="..\Discord.Net\Helpers\Http.cs"> | ||||
| <Link>Helpers\Http.cs</Link> | <Link>Helpers\Http.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| <Compile Include="..\Discord.Net\Helpers\HttpException.cs"> | |||||
| <Link>Helpers\HttpException.cs</Link> | |||||
| </Compile> | |||||
| <Compile Include="..\Discord.Net\Invite.cs"> | <Compile Include="..\Discord.Net\Invite.cs"> | ||||
| <Link>Invite.cs</Link> | <Link>Invite.cs</Link> | ||||
| </Compile> | </Compile> | ||||
| @@ -7,7 +7,7 @@ | |||||
| <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" /> | ||||
| <PropertyGroup Label="Globals"> | <PropertyGroup Label="Globals"> | ||||
| <ProjectGuid>acfb060b-ec8a-4926-b293-04c01e17ee23</ProjectGuid> | <ProjectGuid>acfb060b-ec8a-4926-b293-04c01e17ee23</ProjectGuid> | ||||
| <RootNamespace>Discord.Net</RootNamespace> | |||||
| <RootNamespace>Discord</RootNamespace> | |||||
| <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath> | ||||
| <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath> | ||||
| </PropertyGroup> | </PropertyGroup> | ||||
| @@ -596,7 +596,7 @@ namespace Discord | |||||
| { | { | ||||
| await DiscordAPI.LeaveServer(serverId); | 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); | return _servers.Remove(serverId); | ||||
| } | } | ||||
| @@ -626,7 +626,7 @@ namespace Discord | |||||
| { | { | ||||
| var response = await DiscordAPI.DestroyChannel(channelId); | 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); | return _channels.Remove(channelId); | ||||
| } | } | ||||
| @@ -655,7 +655,7 @@ namespace Discord | |||||
| { | { | ||||
| await DiscordAPI.Unban(serverId, userId); | 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 | //Invites | ||||
| @@ -718,7 +718,7 @@ namespace Discord | |||||
| var response = await DiscordAPI.GetInvite(id); | var response = await DiscordAPI.GetInvite(id); | ||||
| await DiscordAPI.DeleteInvite(response.Code); | 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 | //Chat | ||||
| @@ -781,8 +781,8 @@ namespace Discord | |||||
| await DiscordAPI.DeleteMessage(channelId, msgId); | await DiscordAPI.DeleteMessage(channelId, msgId); | ||||
| return _messages.Remove(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; | return null; | ||||
| } | } | ||||
| @@ -134,14 +134,14 @@ namespace Discord.Helpers | |||||
| { | { | ||||
| response = await _client.SendAsync(msg, HttpCompletionOption.ResponseContentRead); | response = await _client.SendAsync(msg, HttpCompletionOption.ResponseContentRead); | ||||
| if (!response.IsSuccessStatusCode) | if (!response.IsSuccessStatusCode) | ||||
| throw new InvalidOperationException($"The server responded with error {(int)response.StatusCode}."); | |||||
| throw new HttpException(response.StatusCode); | |||||
| result = await response.Content.ReadAsStringAsync(); | result = await response.Content.ReadAsStringAsync(); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| response = await _client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead); | response = await _client.SendAsync(msg, HttpCompletionOption.ResponseHeadersRead); | ||||
| if (!response.IsSuccessStatusCode) | if (!response.IsSuccessStatusCode) | ||||
| throw new InvalidOperationException($"The server responded with error {(int)response.StatusCode}."); | |||||
| throw new HttpException(response.StatusCode); | |||||
| result = null; | result = null; | ||||
| } | } | ||||
| @@ -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": { | "dependencies": { | ||||
| "Newtonsoft.Json": "7.0.1", | |||||
| "Microsoft.Net.Http": "2.2.22" | |||||
| "Newtonsoft.Json": "7.0.1" | |||||
| }, | }, | ||||
| "frameworks": { | "frameworks": { | ||||
| "net45": { }, | |||||
| "dnx451": { }, | |||||
| "net45": { | |||||
| "dependencies": { | |||||
| "Microsoft.Net.Http": "2.2.22" | |||||
| } | |||||
| }, | |||||
| "dnx451": { | |||||
| "dependencies": { | |||||
| "Microsoft.Net.Http": "2.2.22" | |||||
| } | |||||
| }, | |||||
| "dnxcore50": { | "dnxcore50": { | ||||
| "dependencies": { | "dependencies": { | ||||
| "System.Collections.Concurrent": "4.0.10", | "System.Collections.Concurrent": "4.0.10", | ||||
| @@ -33,4 +40,4 @@ | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | |||||
| } | |||||