增加错误日志记录报文
This commit is contained in:
parent
472e684449
commit
78d3015aa4
|
|
@ -61,27 +61,38 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error {
|
|||
return ctx.JSON(200, reply)
|
||||
}
|
||||
|
||||
func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||
func (s *VoucherService) readBody(bodyBytes []byte) (*v1.CmbRequest, error) {
|
||||
|
||||
var req *v1.CmbRequest
|
||||
if err := json.Unmarshal(bodyBytes, &req); err != nil {
|
||||
return nil, err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
if err := req.Validate(); err != nil {
|
||||
return nil, err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
return req, nil
|
||||
}
|
||||
|
||||
func (v *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
||||
|
||||
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||
if err != nil {
|
||||
return "", err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
var req *v1.CmbRequest
|
||||
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||
return "", err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
if err = req.Validate(); err != nil {
|
||||
return "", err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
bizContent, err := s.CmbMixRepo.OrderVerify(ctx, req)
|
||||
req, err := v.readBody(bodyBytes)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
bizContent, err := v.CmbMixRepo.OrderVerify(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("cmbOrder body: %s", string(bodyBytes))
|
||||
return "", err
|
||||
}
|
||||
|
||||
boReq := &bo.OrderCreateReqBo{
|
||||
OutBizNo: bizContent.TransactionId,
|
||||
ProductNo: bizContent.ActivityId,
|
||||
|
|
@ -92,7 +103,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
|||
Type: vo.OrderTypeCmb,
|
||||
}
|
||||
|
||||
orderNo, err := s.VoucherBiz.CmbOrder(ctx, boReq)
|
||||
orderNo, err := v.VoucherBiz.CmbOrder(ctx, boReq)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -100,69 +111,6 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (string, error) {
|
|||
return orderNo, nil
|
||||
}
|
||||
|
||||
func (s *VoucherService) CmbQuery(ctx http.Context) error {
|
||||
|
||||
var (
|
||||
reply *v1.CmbReply
|
||||
|
||||
req = &bo.CmbResponseBo{}
|
||||
)
|
||||
|
||||
bizReply, err := s.cmbQuery(ctx)
|
||||
if err != nil {
|
||||
//se := errors.FromError(err)
|
||||
//
|
||||
//if len(se.Reason) == 0 {
|
||||
// se.Reason = err2.CmbErr_CMB_UNKNOWN.String()
|
||||
//}
|
||||
|
||||
req.RespCode = vo.CmbResponseStatusFail.GetValue()
|
||||
req.RespMsg = err.Error()
|
||||
req.BizContent = ""
|
||||
|
||||
log.Errorf("CmbQuery: %v", err)
|
||||
} else {
|
||||
|
||||
replyBizContentBytes, _ := json.Marshal(bizReply)
|
||||
|
||||
req.RespCode = vo.CmbResponseStatusSuccess.GetValue()
|
||||
req.RespMsg = "成功"
|
||||
req.BizContent = string(replyBizContentBytes)
|
||||
}
|
||||
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("cmbProductQuery GetResponse: %v", err)
|
||||
return ctx.JSON(400, err)
|
||||
}
|
||||
|
||||
return ctx.JSON(200, reply)
|
||||
}
|
||||
|
||||
func (s *VoucherService) cmbQuery(ctx http.Context) (*v1.CmbQueryReply, error) {
|
||||
|
||||
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var req *v1.CmbRequest
|
||||
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bizContent, err := s.CmbMixRepo.QueryVerify(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.VoucherBiz.CmbQuery(ctx, bizContent.CodeNo)
|
||||
}
|
||||
|
||||
func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
||||
|
||||
var (
|
||||
|
|
@ -204,26 +152,81 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error {
|
|||
return ctx.JSON(200, reply)
|
||||
}
|
||||
|
||||
func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
||||
func (v *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductReply, error) {
|
||||
|
||||
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
var req *v1.CmbRequest
|
||||
if err = json.Unmarshal(bodyBytes, &req); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = req.Validate(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bizContent, err := s.CmbMixRepo.ProductQueryVerify(ctx, req)
|
||||
req, err := v.readBody(bodyBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
||||
bizContent, err := v.CmbMixRepo.ProductQueryVerify(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("cmbProductQuery body: %s", string(bodyBytes))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return v.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
|
||||
}
|
||||
|
||||
func (s *VoucherService) CmbQuery(ctx http.Context) error {
|
||||
|
||||
var (
|
||||
reply *v1.CmbReply
|
||||
|
||||
req = &bo.CmbResponseBo{}
|
||||
)
|
||||
|
||||
bizReply, err := s.cmbQuery(ctx)
|
||||
if err != nil {
|
||||
//se := errors.FromError(err)
|
||||
//
|
||||
//if len(se.Reason) == 0 {
|
||||
// se.Reason = err2.CmbErr_CMB_UNKNOWN.String()
|
||||
//}
|
||||
req.RespCode = vo.CmbResponseStatusFail.GetValue()
|
||||
req.RespMsg = err.Error()
|
||||
req.BizContent = ""
|
||||
|
||||
log.Errorf("CmbQuery: %v", err)
|
||||
} else {
|
||||
|
||||
replyBizContentBytes, _ := json.Marshal(bizReply)
|
||||
|
||||
req.RespCode = vo.CmbResponseStatusSuccess.GetValue()
|
||||
req.RespMsg = "成功"
|
||||
req.BizContent = string(replyBizContentBytes)
|
||||
}
|
||||
|
||||
reply, err = s.CmbMixRepo.GetResponse(ctx, req)
|
||||
if err != nil {
|
||||
log.Errorf("cmbProductQuery GetResponse: %v", err)
|
||||
return ctx.JSON(400, err)
|
||||
}
|
||||
|
||||
return ctx.JSON(200, reply)
|
||||
}
|
||||
|
||||
func (v *VoucherService) cmbQuery(ctx http.Context) (*v1.CmbQueryReply, error) {
|
||||
|
||||
bodyBytes, err := io.ReadAll(ctx.Request().Body)
|
||||
if err != nil {
|
||||
return nil, err2.ErrorCmbParamFail(err.Error())
|
||||
}
|
||||
|
||||
req, err := v.readBody(bodyBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
bizContent, err := v.CmbMixRepo.QueryVerify(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return v.VoucherBiz.CmbQuery(ctx, bizContent.CodeNo)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue