包装错误信息
This commit is contained in:
parent
c9bd4612f2
commit
e8967efc9d
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
||||
"io"
|
||||
"net/http"
|
||||
"voucher/internal/biz/bo"
|
||||
"voucher/internal/biz/vo"
|
||||
|
|
@ -52,7 +53,20 @@ func (c *CpnRepoImpl) Order(ctx context.Context, orderWechat *bo.OrderWechatBo)
|
|||
svc := cashcoupons.CouponApiService{Client: client}
|
||||
|
||||
resp, result, err := svc.SendCoupon(ctx, req)
|
||||
|
||||
if err != nil {
|
||||
|
||||
bodyBytes, err := io.ReadAll(result.Response.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = fmt.Errorf("微信返回错误=%s", ErrBody.Message)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -83,7 +97,16 @@ func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderWechatBo)
|
|||
|
||||
resp, result, err := svc.QueryCoupon(ctx, req)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
bodyBytes, err := io.ReadAll(result.Response.Body)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return 0, fmt.Errorf("微信返回错误=%s", ErrBody.Message)
|
||||
}
|
||||
|
||||
if result.Response.StatusCode != CodeSuccess {
|
||||
|
|
@ -109,7 +132,16 @@ func (c *CpnRepoImpl) QueryProduct(ctx context.Context, stockCreatorMchId, stock
|
|||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
bodyBytes, err := io.ReadAll(result.Response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(bodyBytes, &ErrBody); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("微信返回错误=%s", ErrBody.Message)
|
||||
}
|
||||
|
||||
if result.Response.StatusCode != CodeSuccess {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
package wechatrepoimpl
|
||||
|
||||
var ErrBody struct {
|
||||
StatusCode string `json:"StatusCode"`
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
}
|
||||
Loading…
Reference in New Issue