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)
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Discord.Net;
|
||||||
using Nancy.Extensions;
|
using Nancy.Extensions;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
using SharpRaven;
|
using SharpRaven;
|
||||||
|
@ -26,7 +28,7 @@ namespace Geekbot.net.Lib
|
||||||
if (!string.IsNullOrEmpty(sentryDsn))
|
if (!string.IsNullOrEmpty(sentryDsn))
|
||||||
{
|
{
|
||||||
_raven = new RavenClient(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
|
else
|
||||||
{
|
{
|
||||||
|
@ -93,7 +95,19 @@ namespace Geekbot.net.Lib
|
||||||
_logger.Error(ex, "Errorception");
|
_logger.Error(ex, "Errorception");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 class ErrorObject
|
||||||
{
|
{
|
||||||
public ErrorMessage Message { get; set; }
|
public ErrorMessage Message { get; set; }
|
||||||
|
@ -123,5 +137,6 @@ namespace Geekbot.net.Lib
|
||||||
public interface IErrorHandler
|
public interface IErrorHandler
|
||||||
{
|
{
|
||||||
void HandleCommandException(Exception e, ICommandContext Context, string errorMessage = "def");
|
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:"
|
"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": {
|
"choose": {
|
||||||
"Choice": {
|
"Choice": {
|
||||||
"EN": "I Choose **{0}**",
|
"EN": "I Choose **{0}**",
|
||||||
|
|
Loading…
Reference in a new issue