Skip to content

Commit

Permalink
update request logging
Browse files Browse the repository at this point in the history
  • Loading branch information
LukePulverenti committed Jul 22, 2017
1 parent acd5339 commit 49206f4
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Emby.Server.Implementations/HttpServer/HttpListenerHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public HttpListenerHost(IServerApplicationHost applicationHost,
readonly Dictionary<Type, int> _mapExceptionToStatusCode = new Dictionary<Type, int>
{
{typeof (ResourceNotFoundException), 404},
{typeof (RemoteServiceUnavailableException), 502},
{typeof (FileNotFoundException), 404},
//{typeof (DirectoryNotFoundException), 404},
{typeof (SecurityException), 401},
Expand Down Expand Up @@ -268,6 +269,29 @@ private void OnWebSocketConnected(WebSocketConnectEventArgs args)
}
}

private Exception GetActualException(Exception ex)
{
var agg = ex as AggregateException;
if (agg != null)
{
var inner = agg.InnerException;
if (inner != null)
{
return GetActualException(inner);
}
else
{
var inners = agg.InnerExceptions;
if (inners != null && inners.Count > 0)
{
return GetActualException(inners[0]);
}
}
}

return ex;
}

private int GetStatusCode(Exception ex)
{
if (ex is ArgumentException)
Expand All @@ -280,7 +304,7 @@ private int GetStatusCode(Exception ex)
int statusCode;
if (!_mapExceptionToStatusCode.TryGetValue(exceptionType, out statusCode))
{
if (string.Equals(exceptionType.Name, "DirectoryNotFoundException", StringComparison.OrdinalIgnoreCase))
if (ex is DirectoryNotFoundException)
{
statusCode = 404;
}
Expand All @@ -297,6 +321,8 @@ private void ErrorHandler(Exception ex, IRequest httpReq, bool logException = tr
{
try
{
ex = GetActualException(ex);

if (logException)
{
_logger.ErrorException("Error processing request", ex);
Expand Down

0 comments on commit 49206f4

Please sign in to comment.