Created
March 3, 2015 09:17
-
-
Save aanufriyev/4bd6b4b19cec0cd5e755 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ScimExceptionFilter] | |
public class ScimEndpoint : Controller | |
{ | |
private static readonly Dictionary<Type, HttpStatusCode> BaseExceptionsMapping = new Dictionary<Type, HttpStatusCode>(); | |
static ScimEndpoint() | |
{ | |
BaseExceptionsMapping.Add(typeof(ScimResourceConstraintException), HttpStatusCode.PreconditionFailed); | |
BaseExceptionsMapping.Add(typeof(ScimResourceConflictException), HttpStatusCode.Conflict); | |
BaseExceptionsMapping.Add(typeof(ScimResourceNotFoundException), HttpStatusCode.NotFound); | |
BaseExceptionsMapping.Add(typeof(InvalidScimOperationException), HttpStatusCode.BadRequest); | |
BaseExceptionsMapping.Add(typeof(NotImplementedException), HttpStatusCode.NotImplemented); | |
} | |
public IDictionary<Type, HttpStatusCode> BaseExceptionsMap => BaseExceptionsToStatusCodeMap; | |
} | |
public class ScimExceptionFilter :ExceptionFilterAttribute | |
{ | |
public override void OnException(ExceptionContext context) | |
{ | |
// Check if controller is ScimEndpoint or subtype | |
// Subtype can have its own map for specific exceptions | |
// Also it can be usefull to use controller as dependency provider like in WebApi2 UrlHelper | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment