Пример #1
0
        public ErrorSummary GetFriendlyResponse(List <KeyValuePair <string, int> > validationErrors, string response)
        {
            var res           = new ErrorSummary();
            var errorsDetails = validationErrors.Select(x =>
            {
                var currentErrorCatalog = errorsInformation.GetErrorCatalogByCode(x.Value);
                var errorDetails        = new ErrorDetails()
                {
                    Location = x.Key,
                    Code     = x.Value,
                    Problem  = currentErrorCatalog.Problem,
                    Action   = currentErrorCatalog.Action
                };
                return(errorDetails);
            }).ToList();

            res.Errors = errorsDetails;
            //res.CorrelationId = currentRequestData.CorrelationId.ToString();
            res.Response = response;
            return(res);
        }
Пример #2
0
        private (ErrorSummary errorSummary, int?httpStatusCode) prepareErrorDetails(Exception exception)
        {
            var res = new ErrorSummary()
            {
                CorrelationId = Guid.NewGuid().ToString()
            };

            switch (exception)
            {
            case DetailedException detailedException:
            {
                var currentErrorCatalog = errorsInformation.GetErrorCatalogByCode(detailedException.LocationCodePairs.Value);
                res.Errors = new List <ErrorDetails>
                {
                    new ErrorDetails()
                    {
                        Location = detailedException.LocationCodePairs.Key,
                        Code     = detailedException.LocationCodePairs.Value,
                        Problem  = (string.IsNullOrEmpty(detailedException.JsonData) ? currentErrorCatalog.Problem : JsonConvert.DeserializeObject <object>(detailedException.JsonData)),
                        Action   = currentErrorCatalog.Action
                    }
                };

                return(res, currentErrorCatalog.HttpResponseCode);
            }

            case XmlException ex1:
            case UnsupportedContentTypeException ex:
            {
                ErrorCatalog currentErrorCatalog;
                string       errorLocation;

                currentErrorCatalog = errorsInformation.GetErrorCatalogByCode(ErrorCodes.UnsupportedMediaTypeHeader);
                errorLocation       = exception.Message;

                var errorDetails = new ErrorDetails()
                {
                    Location = errorLocation,
                    Code     = currentErrorCatalog.Code,
                    Problem  = currentErrorCatalog.Problem,
                    Action   = currentErrorCatalog.Action
                };
                res.Errors.Add(errorDetails);
                return(res, currentErrorCatalog.HttpResponseCode);
            }

            default:
            {
                var currentErrorCatalog = errorsInformation.GetErrorCatalogByCode(ErrorCodes.UnrecoverableTechnicalIssue);
                var errorDetails        = new ErrorDetails()
                {
                    Location = "Service",
                    Code     = currentErrorCatalog.Code,
                    Problem  = currentErrorCatalog.Problem,
                    Action   = currentErrorCatalog.Action
                };
                res.Errors.Add(errorDetails);
                return(res, currentErrorCatalog.HttpResponseCode);
            }
            }
        }