Initial project commit
This commit is contained in:
48
TorControlLibrary/Exceptions/TorException.cs
Normal file
48
TorControlLibrary/Exceptions/TorException.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace TorControlLibrary.Exceptions
|
||||
{
|
||||
public class TorException : System.Exception
|
||||
{
|
||||
public static TorException Parse(String errorLine)
|
||||
{
|
||||
TorException ex = null;
|
||||
switch (errorLine.Substring(0, 3))
|
||||
{
|
||||
case "552":
|
||||
if (errorLine.Contains("Unknown stream"))
|
||||
ex = new TorUnknownStreamException()
|
||||
{
|
||||
StreamID = Int32.Parse(errorLine.Substring(errorLine.IndexOf('"') + 1, errorLine.Length - (errorLine.LastIndexOf('"') + 1)))
|
||||
};
|
||||
else if (errorLine.Contains("Unknown circuit"))
|
||||
ex = new TorUnknownCircuitException()
|
||||
{
|
||||
CircuitID = Int32.Parse(errorLine.Substring(errorLine.IndexOf('"') + 1, errorLine.Length - (errorLine.LastIndexOf('"') + 1)))
|
||||
};
|
||||
else
|
||||
ex = new TorException();
|
||||
break;
|
||||
case "551":
|
||||
if (errorLine.Contains("one-hop circuit"))
|
||||
{
|
||||
ex = new TorOneCircuitException();
|
||||
}
|
||||
break;
|
||||
case "515":
|
||||
ex = new TorAuthenticationException();
|
||||
break;
|
||||
default:
|
||||
throw new ApplicationException("Unhandled exception from TOR control port");
|
||||
}
|
||||
ex.ErrorDescription = errorLine.Substring(4);
|
||||
ex.StatusCode = Int32.Parse(errorLine.Substring(0, 3));
|
||||
return ex;
|
||||
}
|
||||
public Int32 StatusCode { get; set; }
|
||||
public String ErrorDescription { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user