forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorsService.cs
More file actions
82 lines (74 loc) · 3.02 KB
/
Copy pathErrorsService.cs
File metadata and controls
82 lines (74 loc) · 3.02 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.IO;
using System.Net;
using Check.ServiceModel;
using ServiceStack;
using ServiceStack.Data;
using ServiceStack.FluentValidation;
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(Return404 request)
{
return HttpError.NotFound("Custom Status Description");
}
public object Any(Return404Result request)
{
return new HttpResult(HttpStatusCode.NotFound, "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.EndRequest();
break;
}
return request;
}
public object Any(ThrowValidation request)
{
return request.ConvertTo<ThrowValidationResponse>();
}
}
public class ThrowValidationValidator : AbstractValidator<ThrowValidation>
{
public ThrowValidationValidator()
{
RuleFor(x => x.Age).InclusiveBetween(1, 120);
RuleFor(x => x.Required).NotEmpty();
RuleFor(x => x.Email).NotEmpty().EmailAddress();
}
}
}