Пример #1
0
        public override void OnException(ExceptionContext context)
        {
            var exception = context.Exception;

            if (exception == null)
            {
                // Should never happen.
                return;
            }

            var error = new ScimError();

            if (exception is BadRequestException)
            {
                context.HttpContext.Response.StatusCode = error.Status = 400;
                error.Detail = exception.Message;
            }
            else if (exception is NotFoundException)
            {
                context.HttpContext.Response.StatusCode = error.Status = 404;
                error.Detail = "Resource not found.";
            }
            else
            {
                context.HttpContext.Response.StatusCode = error.Status = 500;
                error.Detail = "An unhandled server error has occurred.";
                var logger = context.HttpContext.RequestServices.GetRequiredService <ILogger <ExceptionHandlerFilterAttribute> >();
                logger.LogError(0, exception, exception.Message);
            }

            context.Result = new ObjectResult(error);
        }
Пример #2
0
        private static HttpStatusCode GetStatusCode(ScimError error)
        {
            if (error != null)
            {
                return(error.Status);
            }

            return(HttpStatusCode.BadRequest);
        }
Пример #3
0
        internal static IScimResponse <T2> CreateGenericErrorResponse <T, T2>(IScimResponse <T> originalResponse, ScimError error)
        {
            if (IsBuiltInErrorResponse(originalResponse))
            {
                return(new ScimErrorResponse <T2>(error));
            }

            try
            {
                return(Activator.CreateInstance(
                           originalResponse.GetType()
                           .GetGenericTypeDefinition()
                           .MakeGenericType(typeof(T2)),
                           error) as IScimResponse <T2>);
            }
            catch (TargetInvocationException)
            {
                // No supportable constructor found! Return default.
                return(new ScimErrorResponse <T2>(error));
            }
        }
Пример #4
0
 public ScimErrorResponse(ScimError error)
 {
     _Error = error;
 }
Пример #5
0
 /// <summary>
 /// Use this to control the type of response status returned to client.
 /// </summary>
 /// <param name="statusCode">HTTP response status code</param>
 /// <param name="detail">body text as raw string</param>
 /// <param name="errorType">Only applicable for status=400</param>
 public ScimException(HttpStatusCode statusCode, string detail, ScimErrorType errorType = null)
 {
     ScimError = new ScimError(statusCode, errorType, detail);
 }
Пример #6
0
 /// <summary>
 /// Use this to control the type of response status returned to client.
 /// </summary>
 /// <param name="statusCode">HTTP response status code</param>
 /// <param name="detail">body text as raw string</param>
 /// <param name="errorType">Only applicable for status=400</param>
 public ScimException(HttpStatusCode statusCode, string detail, ScimErrorType errorType = null)
 {
     ScimError = new ScimError(statusCode, errorType, detail);
 }