Skip to content

Commit

Permalink
Add Errors Services
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Feb 1, 2015
1 parent da6e8b7 commit f6e261d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
40 changes: 39 additions & 1 deletion tests/Check.ServiceInterface/ErrorsService.cs
@@ -1,5 +1,9 @@
using Check.ServiceModel;
using System;
using System.IO;
using System.Security.Authentication;
using Check.ServiceModel;
using ServiceStack;
using ServiceStack.Data;

namespace Check.ServiceInterface
{
Expand All @@ -14,5 +18,39 @@ 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;
}
}
}
12 changes: 12 additions & 0 deletions tests/Check.ServiceModel/ThrowHttpError.cs
Expand Up @@ -15,4 +15,16 @@ public class Throw404
{
public string Message { get; set; }
}

[Route("/throw/{Type}")]
public class ThrowType : IReturn<ThrowTypeResponse>
{
public string Type { get; set; }
public string Message { get; set; }
}

public class ThrowTypeResponse
{
public ResponseStatus ResponseStatus { get; set; }
}
}
1 change: 1 addition & 0 deletions tests/CheckWeb/Global.asax.cs
Expand Up @@ -76,6 +76,7 @@ public override void Configure(Container container)

Plugins.Add(new AutoQueryFeature());
Plugins.Add(new PostmanFeature());
Plugins.Add(new CorsFeature());

container.Register<IDbConnectionFactory>(
new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));
Expand Down

0 comments on commit f6e261d

Please sign in to comment.