Skip to content

Instantly share code, notes, and snippets.

@aanufriyev
Created March 3, 2015 09:17
Show Gist options
  • Save aanufriyev/4bd6b4b19cec0cd5e755 to your computer and use it in GitHub Desktop.
Save aanufriyev/4bd6b4b19cec0cd5e755 to your computer and use it in GitHub Desktop.
[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