Ejemplo n.º 1
0
        private void SetExceptionType(ExceptionContext context, ErrorDetailModel errorDetail)
        {
            var exceptionType = context.Exception.GetType();

            switch (exceptionType.Name)
            {
            // Checking for Business Exceptions
            case nameof(DbUpdateException):
                errorDetail.Type = "Data Base";
                break;

            case nameof(DbUpdateConcurrencyException):
                errorDetail.Type = "Data Base";
                break;

            default:
                errorDetail.Type = "Technical";
                break;
            }
        }
Ejemplo n.º 2
0
        public void OnException(ExceptionContext context)
        {
            var errorDetail = new ErrorDetailModel
            {
                State = HttpStatusCode.InternalServerError.ToString(),
                Code  = (int)HttpStatusCode.InternalServerError
            };

            SetExceptionType(context, errorDetail);

            errorDetail.Detail = context.Exception.Message;
            errorDetail.Errors.Add(new Error
            {
                Code       = SetErrorCode(context),
                Title      = context.Exception.Message,
                Detail     = context.Exception.InnerException?.Message ?? string.Empty,
                Source     = context.Exception.Source,
                SpvTrackId = context.HttpContext.TraceIdentifier
            });

            context.Result = new ObjectResult(errorDetail);
            context.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
        }