Add httpErrorHandler

This commit is contained in:
Runebaas 2017-11-27 22:07:05 +01:00
parent c4f10f3f7b
commit 53debf9c9d
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
3 changed files with 24 additions and 3 deletions

View file

@ -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)
{

View file

@ -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);
}
}

View file

@ -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}**",