Exemple #1
0
        private static (ErrorResponse, List <ErrorResponse>) GetOperationResultResponse(
            OperationResult operationResult, bool isInternal,
            Func <ActionStatus, string> beautifulMessageFunc = null,
            Func <ActionStatus, string> customErrorCodeFunc  = null)
        {
            var mainError = new ErrorResponse
            {
                Error  = CommonBehavior.GetError(operationResult.ActionStatus, customErrorCodeFunc),
                Reason = CommonBehavior.GetMessage(
                    beautifulMessageFunc,
                    operationResult.ActionStatus,
                    operationResult.DumpAllErrors(),
                    operationResult.DumpPublicErrors(),
                    CommonBehavior.GetDefaultMessage(operationResult.ActionStatus),
                    isInternal)
            };
            var errorList = new List <ErrorResponse>(operationResult.Errors.Count);

            if (operationResult.Errors.Count > 1)
            {
                errorList = operationResult.Errors.Select(res => new ErrorResponse
                {
                    Error  = CommonBehavior.GetError(res.ActionStatus, customErrorCodeFunc),
                    Reason = CommonBehavior.GetMessage(
                        beautifulMessageFunc,
                        res.ActionStatus,
                        res.ErrorMessage,
                        res.IsInternal ? null : res.ErrorMessage,
                        CommonBehavior.GetDefaultMessage(res.ActionStatus),
                        isInternal)
                }).ToList();
            }
            return(mainError, errorList);
        }