Better error message when port is in use

This commit is contained in:
Mark McDowall 2013-09-11 08:35:58 -07:00
parent 94f64567c6
commit 89a72a50cf
3 changed files with 38 additions and 1 deletions

View File

@ -125,6 +125,7 @@
<Compile Include="Owin\NlogTextWriter.cs" /> <Compile Include="Owin\NlogTextWriter.cs" />
<Compile Include="Owin\OwinServiceProvider.cs" /> <Compile Include="Owin\OwinServiceProvider.cs" />
<Compile Include="Owin\OwinTraceOutputFactory.cs" /> <Compile Include="Owin\OwinTraceOutputFactory.cs" />
<Compile Include="Owin\PortInUseException.cs" />
<Compile Include="PlatformValidation.cs" /> <Compile Include="PlatformValidation.cs" />
<Compile Include="MainAppContainerBuilder.cs" /> <Compile Include="MainAppContainerBuilder.cs" />
<Compile Include="ApplicationModes.cs" /> <Compile Include="ApplicationModes.cs" />

View File

@ -1,6 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Reflection;
using Microsoft.Owin.Hosting; using Microsoft.Owin.Hosting;
using NLog; using NLog;
using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.EnvironmentInfo;
@ -50,7 +52,26 @@ namespace NzbDrone.Host.Owin
_logger.Info("starting server on {0}", _urlAclAdapter.UrlAcl); _logger.Info("starting server on {0}", _urlAclAdapter.UrlAcl);
_host = WebApp.Start(OwinServiceProviderFactory.Create(), options, BuildApp); try
{
_host = WebApp.Start(OwinServiceProviderFactory.Create(), options, BuildApp);
}
catch (TargetInvocationException ex)
{
if (ex.InnerException == null)
{
throw ex;
}
if (ex.InnerException as HttpListenerException == null)
{
throw ex;
}
throw new PortInUseException("Port {0} is already in use, please ensure NzbDrone is not already running.",
ex,
_configFileProvider.Port);
}
} }
private void BuildApp(IAppBuilder appBuilder) private void BuildApp(IAppBuilder appBuilder)

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Common.Exceptions;
namespace NzbDrone.Host.Owin
{
public class PortInUseException : NzbDroneException
{
public PortInUseException(string message, Exception innerException, params object[] args) : base(message, innerException, args)
{
}
}
}