- write detail log when eml call failed.
This commit is contained in:
@@ -62,7 +62,7 @@ type payload struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func New(token, appKey, secret string, isProd bool, config ...*platformapi.APIConfig) *API {
|
func New(token, appKey, secret string, isProd bool, config ...*platformapi.APIConfig) *API {
|
||||||
baseapi.SugarLogger.Debugf("token=%v, appKey=%v, secret=%v", token, appKey, secret)
|
// baseapi.SugarLogger.Debugf("token=%v, appKey=%v, secret=%v", token, appKey, secret)
|
||||||
curConfig := platformapi.DefAPIConfig
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
curConfig = *config[0]
|
curConfig = *config[0]
|
||||||
@@ -84,16 +84,16 @@ func New(token, appKey, secret string, isProd bool, config ...*platformapi.APICo
|
|||||||
return api
|
return api
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) SetToken(newToken string) bool {
|
func (a *API) SetToken(newToken string) (retVal bool) {
|
||||||
curToken := a.GetToken()
|
curToken := a.GetToken()
|
||||||
if curToken != newToken {
|
if curToken != newToken {
|
||||||
a.locker.Lock()
|
a.locker.Lock()
|
||||||
defer a.locker.Unlock()
|
defer a.locker.Unlock()
|
||||||
a.token = newToken
|
a.token = newToken
|
||||||
return true
|
retVal = true
|
||||||
|
baseapi.SugarLogger.Debugf("elm token changed from %v to %v", curToken, newToken)
|
||||||
}
|
}
|
||||||
|
return retVal
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *API) GetToken() string {
|
func (a *API) GetToken() string {
|
||||||
@@ -148,6 +148,7 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
|
|||||||
|
|
||||||
pl.Signature = a.signParams(action, pl)
|
pl.Signature = a.signParams(action, pl)
|
||||||
|
|
||||||
|
bodyStr := string(utils.MustMarshal(pl))
|
||||||
request := &http.Request{
|
request := &http.Request{
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
URL: a.url,
|
URL: a.url,
|
||||||
@@ -158,7 +159,7 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
|
|||||||
// "x-eleme-requestid": []string{payload.Id},
|
// "x-eleme-requestid": []string{payload.Id},
|
||||||
},
|
},
|
||||||
|
|
||||||
Body: ioutil.NopCloser(strings.NewReader(string(utils.MustMarshal(pl)))),
|
Body: ioutil.NopCloser(strings.NewReader(bodyStr)),
|
||||||
}
|
}
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client, request, a.config, func(response *http.Response) (result string, err error) {
|
err = platformapi.AccessPlatformAPIWithRetry(a.client, request, a.config, func(response *http.Response) (result string, err error) {
|
||||||
jsonResult1, err := utils.HTTPResponse2Json(response)
|
jsonResult1, err := utils.HTTPResponse2Json(response)
|
||||||
@@ -176,7 +177,7 @@ func (a *API) AccessAPI(action string, params map[string]interface{}) (retVal *R
|
|||||||
return platformapi.ErrLevelSuccess, nil
|
return platformapi.ErrLevelSuccess, nil
|
||||||
}
|
}
|
||||||
code := errinfoMap["code"].(string)
|
code := errinfoMap["code"].(string)
|
||||||
baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v, payload:%v", jsonResult1, code, pl)
|
baseapi.SugarLogger.Warnf("response business code is not ok, data:%v, code:%v, bodyStr:%v", jsonResult1, code, bodyStr)
|
||||||
newErr := utils.NewErrorCode(errinfoMap["message"].(string), code)
|
newErr := utils.NewErrorCode(errinfoMap["message"].(string), code)
|
||||||
if code == "EXCEED_LIMIT" {
|
if code == "EXCEED_LIMIT" {
|
||||||
return platformapi.ErrLevelExceedLimit, newErr
|
return platformapi.ErrLevelExceedLimit, newErr
|
||||||
|
|||||||
@@ -20,14 +20,13 @@ func init() {
|
|||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
// sandbox
|
// sandbox
|
||||||
elmapi = New("f22acad55e8b11ae146ad9295e20cf4e", "RwT214gAsS", "56afff4b9ebd8a7eb532d18fa33f17be57f9b9db", false)
|
elmapi = New("7b642f1767b6ad5c074238f1bf4720f8", "RwT214gAsS", "56afff4b9ebd8a7eb532d18fa33f17be57f9b9db", false)
|
||||||
|
|
||||||
// prod
|
// prod
|
||||||
// elmapi = New("a530ade4a8e0b99542df0592b06575b5", "KLRDcOZGrk", "1fc221f8265506531da36fb613d5f5ad673f2e9a", true)
|
// elmapi = New("a530ade4a8e0b99542df0592b06575b5", "KLRDcOZGrk", "1fc221f8265506531da36fb613d5f5ad673f2e9a", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTest(t *testing.T) {
|
func TestTest(t *testing.T) {
|
||||||
q
|
|
||||||
sugarLogger.Debug(utils.GetCurTimeStr())
|
sugarLogger.Debug(utils.GetCurTimeStr())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user