Exemplo n.º 1
0
        public static APIResult Build(bool aPIResultStatus,
                                      int statusCodes = StatusCodes.Status200OK, ErrorMessageEnum errorMessageEnum = ErrorMessageEnum.None,
                                      object payload  = null, string exceptionMessage = "", bool replaceExceptionMessage = true)
        {
            APIResult apiResult = new APIResult()
            {
                Status     = aPIResultStatus,
                ErrorCode  = (int)errorMessageEnum,
                Message    = (errorMessageEnum == ErrorMessageEnum.None) ? "" : $"錯誤代碼 {(int)errorMessageEnum}, {ErrorMessageMapping.Instance.GetErrorMessage(errorMessageEnum)}",
                HTTPStatus = statusCodes,
                Payload    = payload,
            };

            if (apiResult.ErrorCode == (int)ErrorMessageEnum.Exception)
            {
                apiResult.Message = $"{apiResult.Message}{exceptionMessage}";
            }
            else if (string.IsNullOrEmpty(exceptionMessage) == false)
            {
                if (replaceExceptionMessage == true)
                {
                    apiResult.Message = $"{exceptionMessage}";
                }
                else
                {
                    apiResult.Message += $"{exceptionMessage}";
                }
            }
            return(apiResult);
        }
Exemplo n.º 2
0
        public string GetErrorMessage(ErrorMessageEnum errorMessageEnum)
        {
            string fooMsg = "";

            if (ErrorMessages.ContainsKey(errorMessageEnum) == true)
            {
                fooMsg = ErrorMessages[errorMessageEnum];
            }
            return(fooMsg);
        }
        public static VerifyRecordResult Build(bool success, ErrorMessageEnum errorMessageEnum = ErrorMessageEnum.None)
        {
            VerifyRecordResult verifyRecordResult = new VerifyRecordResult()
            {
                Success   = success,
                MessageId = errorMessageEnum,
            };

            return(verifyRecordResult);
        }