|
|
@ -91,16 +91,12 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
|
|
|
|
|
|
|
|
readonly Dictionary<Type, int> _mapExceptionToStatusCode = new Dictionary<Type, int>
|
|
|
|
readonly Dictionary<Type, int> _mapExceptionToStatusCode = new Dictionary<Type, int>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{typeof (InvalidOperationException), 500},
|
|
|
|
|
|
|
|
{typeof (NotImplementedException), 500},
|
|
|
|
|
|
|
|
{typeof (ResourceNotFoundException), 404},
|
|
|
|
{typeof (ResourceNotFoundException), 404},
|
|
|
|
{typeof (FileNotFoundException), 404},
|
|
|
|
{typeof (FileNotFoundException), 404},
|
|
|
|
//{typeof (DirectoryNotFoundException), 404},
|
|
|
|
//{typeof (DirectoryNotFoundException), 404},
|
|
|
|
{typeof (SecurityException), 401},
|
|
|
|
{typeof (SecurityException), 401},
|
|
|
|
{typeof (PaymentRequiredException), 402},
|
|
|
|
{typeof (PaymentRequiredException), 402},
|
|
|
|
{typeof (UnauthorizedAccessException), 500},
|
|
|
|
{typeof (ArgumentException), 400}
|
|
|
|
{typeof (PlatformNotSupportedException), 500},
|
|
|
|
|
|
|
|
{typeof (NotSupportedException), 500}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
public override void Configure()
|
|
|
|
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)
|
|
|
|
private void ErrorHandler(Exception ex, IRequest httpReq, bool logException = true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
@ -244,11 +256,7 @@ namespace Emby.Server.Implementations.HttpServer
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int statusCode;
|
|
|
|
var statusCode = GetStatusCode(ex);
|
|
|
|
if (!_mapExceptionToStatusCode.TryGetValue(ex.GetType(), out statusCode))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
statusCode = 500;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
httpRes.StatusCode = statusCode;
|
|
|
|
httpRes.StatusCode = statusCode;
|
|
|
|
|
|
|
|
|
|
|
|
httpRes.ContentType = "text/html";
|
|
|
|
httpRes.ContentType = "text/html";
|
|
|
|