aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/HttpServer
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-12-27 02:24:44 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-12-27 02:24:44 -0500
commit0b53004c61da66f99dd589a49bd9de948c32e6f8 (patch)
tree3da9785e6b4b890a4f43afe0f1734db75942895c /Emby.Server.Implementations/HttpServer
parentcb8751f985739cef6eefdda83b80f5ede9cc9a80 (diff)
update exception response mapping
Diffstat (limited to 'Emby.Server.Implementations/HttpServer')
-rw-r--r--Emby.Server.Implementations/HttpServer/HttpListenerHost.cs28
1 files changed, 18 insertions, 10 deletions
diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
index 83885ee2e..4e7dc8836 100644
--- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
+++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
@@ -91,16 +91,12 @@ namespace Emby.Server.Implementations.HttpServer
readonly Dictionary<Type, int> _mapExceptionToStatusCode = new Dictionary<Type, int>
{
- {typeof (InvalidOperationException), 500},
- {typeof (NotImplementedException), 500},
{typeof (ResourceNotFoundException), 404},
{typeof (FileNotFoundException), 404},
//{typeof (DirectoryNotFoundException), 404},
{typeof (SecurityException), 401},
{typeof (PaymentRequiredException), 402},
- {typeof (UnauthorizedAccessException), 500},
- {typeof (PlatformNotSupportedException), 500},
- {typeof (NotSupportedException), 500}
+ {typeof (ArgumentException), 400}
};
public override void Configure()
@@ -228,6 +224,22 @@ namespace Emby.Server.Implementations.HttpServer
}
}
+ private int GetStatusCode(Exception ex)
+ {
+ if (ex is ArgumentException)
+ {
+ return 400;
+ }
+
+ int statusCode;
+ if (!_mapExceptionToStatusCode.TryGetValue(ex.GetType(), out statusCode))
+ {
+ statusCode = 500;
+ }
+
+ return statusCode;
+ }
+
private void ErrorHandler(Exception ex, IRequest httpReq, bool logException = true)
{
try
@@ -244,11 +256,7 @@ namespace Emby.Server.Implementations.HttpServer
return;
}
- int statusCode;
- if (!_mapExceptionToStatusCode.TryGetValue(ex.GetType(), out statusCode))
- {
- statusCode = 500;
- }
+ var statusCode = GetStatusCode(ex);
httpRes.StatusCode = statusCode;
httpRes.ContentType = "text/html";