2013-09-16 18:14:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Exceptions
|
|
|
|
|
{
|
|
|
|
|
public static class StatusCodeToExceptions
|
|
|
|
|
{
|
|
|
|
|
public static void VerifyStatusCode(this HttpStatusCode statusCode, string message = null)
|
|
|
|
|
{
|
|
|
|
|
if (String.IsNullOrEmpty(message))
|
|
|
|
|
{
|
|
|
|
|
message = statusCode.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (statusCode)
|
|
|
|
|
{
|
|
|
|
|
case HttpStatusCode.BadRequest:
|
2013-09-26 02:51:07 +00:00
|
|
|
|
throw new BadRequestException(message);
|
2013-09-16 18:14:09 +00:00
|
|
|
|
|
|
|
|
|
case HttpStatusCode.Unauthorized:
|
|
|
|
|
throw new UnauthorizedAccessException(message);
|
|
|
|
|
|
|
|
|
|
case HttpStatusCode.PaymentRequired:
|
|
|
|
|
throw new DownstreamException(statusCode, message);
|
|
|
|
|
|
|
|
|
|
case HttpStatusCode.InternalServerError:
|
|
|
|
|
throw new DownstreamException(statusCode, message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|