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