Add httpErrorHandler
This commit is contained in:
parent
c4f10f3f7b
commit
53debf9c9d
3 changed files with 24 additions and 3 deletions
|
@ -83,7 +83,7 @@ namespace Geekbot.net.Commands
|
|||
}
|
||||
catch (HttpException e)
|
||||
{
|
||||
await Context.Channel.SendMessageAsync("Seems like i don't have enough permission to give roles...");
|
||||
_errorHandler.HandleHttpException(e, Context);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Security.Principal;
|
||||
using Discord.Commands;
|
||||
using Discord.Net;
|
||||
using Nancy.Extensions;
|
||||
using Serilog;
|
||||
using SharpRaven;
|
||||
|
@ -26,7 +28,7 @@ namespace Geekbot.net.Lib
|
|||
if (!string.IsNullOrEmpty(sentryDsn))
|
||||
{
|
||||
_raven = new RavenClient(sentryDsn);
|
||||
_logger.Information($"Command Errors will be logged to Sentry: {sentryDsn}");
|
||||
_logger.Information($"[Geekbot] Command Errors will be logged to Sentry: {sentryDsn}");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -94,6 +96,18 @@ namespace Geekbot.net.Lib
|
|||
}
|
||||
}
|
||||
|
||||
public async void HandleHttpException(HttpException e, ICommandContext Context)
|
||||
{
|
||||
var errorStrings = _translation.GetDict(Context, "httpErrors");
|
||||
switch(e.HttpCode)
|
||||
{
|
||||
case HttpStatusCode.Forbidden:
|
||||
await Context.Channel.SendMessageAsync(errorStrings["403"]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ErrorObject
|
||||
{
|
||||
public ErrorMessage Message { get; set; }
|
||||
|
@ -123,5 +137,6 @@ namespace Geekbot.net.Lib
|
|||
public interface IErrorHandler
|
||||
{
|
||||
void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "def");
|
||||
void HandleHttpException(HttpException e, ICommandContext Context);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,12 @@
|
|||
"CHDE": "Öppis isch schief gange :confused:"
|
||||
}
|
||||
},
|
||||
"httpErrors": {
|
||||
"403": {
|
||||
"EN": "Seems like i don't have enough permission to that :confused:",
|
||||
"CHDE": "Gseht danach us das ich nid gnueg recht han zum das mache :confused:"
|
||||
}
|
||||
},
|
||||
"choose": {
|
||||
"Choice": {
|
||||
"EN": "I Choose **{0}**",
|
||||
|
|
Loading…
Reference in a new issue