Integrate global care #2

Merged
luuvansinh merged 13 commits from integrate-global-care into master 2022-09-12 08:13:42 +00:00
1 changed files with 7 additions and 0 deletions
Showing only changes of commit bc3db15466 - Show all commits

View File

@ -7,6 +7,7 @@ import (
"crypto/sha256" "crypto/sha256"
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"github.com/Selly-Modules/logger" "github.com/Selly-Modules/logger"
@ -97,24 +98,30 @@ func (c *Client) CreateOrder(p CreateOrderPayload) (*CreateOrderResponseDecoded,
res CommonResponse res CommonResponse
) )
if err = pjson.Unmarshal(msg.Data, &r); err != nil { if err = pjson.Unmarshal(msg.Data, &r); err != nil {
log.Printf("globalcare.Client.CreateOrder - pjson.Unmarshal %v, %s\n", err, string(msg.Data))
return nil, err return nil, err
} }
if err = r.ParseResponseData(&res); err != nil { if err = r.ParseResponseData(&res); err != nil {
log.Printf("globalcare.Client.CreateOrder - ParseResponseData %v, %s\n", err, string(msg.Data))
return nil, err return nil, err
} }
if r.Response == nil { if r.Response == nil {
log.Println("globalcare.Client.CreateOrder - nil response")
return nil, fmt.Errorf("globalcare.Client.CreateOrder create_order_empty_response") return nil, fmt.Errorf("globalcare.Client.CreateOrder create_order_empty_response")
} }
if r.Response.StatusCode >= http.StatusBadRequest { if r.Response.StatusCode >= http.StatusBadRequest {
log.Println("globalcare.Client.CreateOrder - bad request", res)
info, err := res.DecodeError() info, err := res.DecodeError()
if err != nil { if err != nil {
log.Println("globalcare.Client.CreateOrder - decode err", err)
return nil, err return nil, err
} }
return nil, errors.New(info.Message) return nil, errors.New(info.Message)
} }
info, err := res.DecodeCreateOrderSuccess() info, err := res.DecodeCreateOrderSuccess()
if err != nil { if err != nil {
log.Println("globalcare.Client.CreateOrder - DecodeCreateOrderSuccess err:", err)
return nil, err return nil, err
} }