/
ErrorsService.cs
56 lines (52 loc) · 2.27 KB
/
ErrorsService.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.IO;
using System.Security.Authentication;
using Check.ServiceModel;
using ServiceStack;
using ServiceStack.Data;
namespace Check.ServiceInterface
{
public class ErrorsService : Service
{
public object Any(ThrowHttpError request)
{
throw new HttpError(request.Status, request.Message);
}
public object Any(Throw404 request)
{
throw HttpError.NotFound(request.Message ?? "Custom Status Description");
}
public object Any(ThrowType request)
{
switch (request.Type ?? "Exception")
{
case "Exception":
throw new Exception(request.Message ?? "Server Error");
case "NotFound":
throw HttpError.NotFound(request.Message ?? "What you're looking for isn't here");
case "Unauthorized":
throw HttpError.Unauthorized(request.Message ?? "You shall not pass!");
case "Conflict":
throw HttpError.Conflict(request.Message ?? "We haz Conflict!");
case "NotImplementedException":
throw new NotImplementedException(request.Message ?? "Not implemented yet, try again later");
case "ArgumentException":
throw new ArgumentException(request.Message ?? "Client Argument Error");
case "AuthenticationException":
throw new AuthenticationException(request.Message ?? "We haz issue Authenticatting");
case "UnauthorizedAccessException":
throw new UnauthorizedAccessException(request.Message ?? "You shall not pass!");
case "OptimisticConcurrencyException":
throw new OptimisticConcurrencyException(request.Message ?? "Sorry too optimistic");
case "UnhandledException":
throw new FileNotFoundException(request.Message ?? "File was never here");
case "RawResponse":
Response.StatusCode = 418;
Response.StatusDescription = request.Message ?? "On a tea break";
Response.Close();
break;
}
return request;
}
}
}