forked from canneverbe/Ketarin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonBinaryFileException.cs
40 lines (36 loc) · 1.37 KB
/
NonBinaryFileException.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Net;
namespace Ketarin
{
/// <summary>
/// This exception should be thrown, if the file to download is
/// not a binary file type.
/// </summary>
internal class NonBinaryFileException : Exception
{
private static string m_Message = "The downloaded file is not a binary file type ({0}). Possibly there is an error page. Status code: {1} ({2})";
/// <summary>
/// Creates a new exception based on the content type and status code.
/// </summary>
public static NonBinaryFileException Create(string contentType, HttpStatusCode code)
{
if (code == HttpStatusCode.NotFound)
{
return new NonBinaryFileException("The file at the specified URL could not be found.");
}
else if (code == HttpStatusCode.Unauthorized)
{
return new NonBinaryFileException("You do not have permission to use access the URL.");
}
return new NonBinaryFileException(contentType, code);
}
private NonBinaryFileException(string msg)
: base(msg)
{
}
private NonBinaryFileException(string contentType, HttpStatusCode code)
: base(string.Format(m_Message, contentType, (int)code, code))
{
}
}
}