包装错误信息
This commit is contained in:
parent
c9bd4612f2
commit
e8967efc9d
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
||||||
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
|
|
@ -52,7 +53,20 @@ func (c *CpnRepoImpl) Order(ctx context.Context, orderWechat *bo.OrderWechatBo)
|
||||||
svc := cashcoupons.CouponApiService{Client: client}
|
svc := cashcoupons.CouponApiService{Client: client}
|
||||||
|
|
||||||
resp, result, err := svc.SendCoupon(ctx, req)
|
resp, result, err := svc.SendCoupon(ctx, req)
|
||||||
|
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,10 +96,19 @@ func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderWechatBo)
|
||||||
svc := cashcoupons.CouponApiService{Client: client}
|
svc := cashcoupons.CouponApiService{Client: client}
|
||||||
|
|
||||||
resp, result, err := svc.QueryCoupon(ctx, req)
|
resp, result, err := svc.QueryCoupon(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
bodyBytes, err := io.ReadAll(result.Response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
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 {
|
if result.Response.StatusCode != CodeSuccess {
|
||||||
err = fmt.Errorf("Query微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
err = fmt.Errorf("Query微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||||
return 0, err
|
return 0, err
|
||||||
|
|
@ -108,10 +131,19 @@ func (c *CpnRepoImpl) QueryProduct(ctx context.Context, stockCreatorMchId, stock
|
||||||
StockCreatorMchid: core.String(stockCreatorMchId),
|
StockCreatorMchid: core.String(stockCreatorMchId),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
bodyBytes, err := io.ReadAll(result.Response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if result.Response.StatusCode != CodeSuccess {
|
||||||
err = fmt.Errorf("查询活动微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
err = fmt.Errorf("查询活动微信返回错误StatusCode[%d]Status[%s]", result.Response.StatusCode, result.Response.Status)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -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