define tnc error code
This commit is contained in:
parent
913d003dfd
commit
1382e57003
|
@ -37,6 +37,10 @@ const (
|
|||
baseURLProd = "https://ext-api.tnclog.vn"
|
||||
)
|
||||
|
||||
const (
|
||||
ErrCodeExistPartnerCode = "exist_partner_code"
|
||||
)
|
||||
|
||||
var (
|
||||
baseURLENVMapping = map[ENV]string{
|
||||
EnvProd: baseURLProd,
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package tnc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Error ...
|
||||
type Error struct {
|
||||
Code string `json:"code"`
|
||||
Message string `json:"errorMessage"`
|
||||
}
|
||||
|
||||
// Error ...
|
||||
func (e Error) Error() string {
|
||||
return fmt.Sprintf("tnc_err: code %s, messsage %s", e.Code, e.Message)
|
||||
}
|
||||
|
||||
// IsErrExistPartnerCode ...
|
||||
func IsErrExistPartnerCode(err error) bool {
|
||||
e, ok := err.(Error)
|
||||
return ok && e.Code == ErrCodeExistPartnerCode
|
||||
}
|
|
@ -5,13 +5,7 @@ type OutboundRequestRes struct {
|
|||
OrID int `json:"orId"`
|
||||
OrCode string `json:"orCode"`
|
||||
PartnerORCode string `json:"partnerORCode"`
|
||||
Error *ErrRes `json:"error"`
|
||||
}
|
||||
|
||||
// ErrRes ...
|
||||
type ErrRes struct {
|
||||
Code string `json:"code"`
|
||||
ErrorMessage string `json:"errorMessage"`
|
||||
Error *Error `json:"error"`
|
||||
}
|
||||
|
||||
type authRes struct {
|
||||
|
|
|
@ -66,7 +66,7 @@ func (c *Client) CreateOutboundRequest(p OutboundRequestPayload) (*OutboundReque
|
|||
}
|
||||
var (
|
||||
r model.CommunicationHttpResponse
|
||||
errRes ErrRes
|
||||
errRes Error
|
||||
dataRes []OutboundRequestRes
|
||||
)
|
||||
if err = pjson.Unmarshal(msg.Data, &r); err != nil {
|
||||
|
@ -80,7 +80,7 @@ func (c *Client) CreateOutboundRequest(p OutboundRequestPayload) (*OutboundReque
|
|||
if err = r.ParseResponseData(&errRes); err != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: parse_response_err: %v", err)
|
||||
}
|
||||
return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: failed code %s, message %s", errRes.Code, errRes.ErrorMessage)
|
||||
return nil, errRes
|
||||
}
|
||||
if err = r.ParseResponseData(&dataRes); err != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: parse_response_data: %v", err)
|
||||
|
@ -91,7 +91,7 @@ func (c *Client) CreateOutboundRequest(p OutboundRequestPayload) (*OutboundReque
|
|||
item := &dataRes[0]
|
||||
e := item.Error
|
||||
if e != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.CreateOutboundRequest: failed, code %s - message %s", e.Code, e.ErrorMessage)
|
||||
return nil, errRes
|
||||
}
|
||||
|
||||
return item, err
|
||||
|
@ -119,7 +119,7 @@ func (c *Client) UpdateOutboundRequestLogisticInfo(p UpdateORLogisticInfoPayload
|
|||
}
|
||||
var (
|
||||
r model.CommunicationHttpResponse
|
||||
errRes ErrRes
|
||||
errRes Error
|
||||
)
|
||||
if err = pjson.Unmarshal(msg.Data, &r); err != nil {
|
||||
return fmt.Errorf("tnc.Client.UpdateOutboundRequestLogisticInfo: parse_data %v", err)
|
||||
|
@ -132,7 +132,7 @@ func (c *Client) UpdateOutboundRequestLogisticInfo(p UpdateORLogisticInfoPayload
|
|||
if err = r.ParseResponseData(&errRes); err != nil {
|
||||
return fmt.Errorf("tnc.Client.UpdateOutboundRequestLogisticInfo: parse_response_err: %v", err)
|
||||
}
|
||||
return fmt.Errorf("tnc.Client.UpdateOutboundRequestLogisticInfo: failed code %s, message %s", errRes.Code, errRes.ErrorMessage)
|
||||
return errRes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -158,7 +158,7 @@ func (c *Client) GetOutboundRequestByID(requestID int) (*OutboundRequestInfo, er
|
|||
}
|
||||
var (
|
||||
r model.CommunicationHttpResponse
|
||||
errRes ErrRes
|
||||
errRes Error
|
||||
outboundRequest OutboundRequestInfo
|
||||
)
|
||||
if err = pjson.Unmarshal(msg.Data, &r); err != nil {
|
||||
|
@ -172,7 +172,7 @@ func (c *Client) GetOutboundRequestByID(requestID int) (*OutboundRequestInfo, er
|
|||
if err = r.ParseResponseData(&errRes); err != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.GetOutboundRequestByID: parse_response_err: %v", err)
|
||||
}
|
||||
return nil, fmt.Errorf("tnc.Client.GetOutboundRequestByID: failed code %s, message %s", errRes.Code, errRes.ErrorMessage)
|
||||
return nil, errRes
|
||||
}
|
||||
if err = r.ParseResponseData(&outboundRequest); err != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.GetOutboundRequestByID: parse_response_data: %v", err)
|
||||
|
@ -203,7 +203,7 @@ func (c *Client) CancelOutboundRequest(requestID int, note string) error {
|
|||
}
|
||||
var (
|
||||
r model.CommunicationHttpResponse
|
||||
errRes ErrRes
|
||||
errRes Error
|
||||
)
|
||||
if err = pjson.Unmarshal(msg.Data, &r); err != nil {
|
||||
return fmt.Errorf("tnc.Client.CancelOutboundRequest: parse_data %v", err)
|
||||
|
@ -216,7 +216,7 @@ func (c *Client) CancelOutboundRequest(requestID int, note string) error {
|
|||
if err = r.ParseResponseData(&errRes); err != nil {
|
||||
return fmt.Errorf("tnc.Client.CancelOutboundRequest: parse_response_err: %v", err)
|
||||
}
|
||||
return fmt.Errorf("tnc.Client.CancelOutboundRequest: failed code %s, message %s", errRes.Code, errRes.ErrorMessage)
|
||||
return errRes
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -252,7 +252,7 @@ func (c *Client) auth() (*authRes, error) {
|
|||
}
|
||||
var (
|
||||
r model.CommunicationHttpResponse
|
||||
errRes ErrRes
|
||||
errRes Error
|
||||
data authRes
|
||||
)
|
||||
if err = pjson.Unmarshal(msg.Data, &r); err != nil {
|
||||
|
@ -266,7 +266,7 @@ func (c *Client) auth() (*authRes, error) {
|
|||
if err = r.ParseResponseData(&errRes); err != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.auth: parse_response_err: %v", err)
|
||||
}
|
||||
return nil, fmt.Errorf("tnc.Client.auth: failed code %s, message %s", errRes.Code, errRes.ErrorMessage)
|
||||
return nil, errRes
|
||||
}
|
||||
if err = r.ParseResponseData(&data); err != nil {
|
||||
return nil, fmt.Errorf("tnc.Client.auth: parse_response_data: %v", err)
|
||||
|
|
Loading…
Reference in New Issue