- write detail log when eml call failed.

This commit is contained in:
gazebo
2018-06-29 18:09:03 +08:00
parent 3a019fcba8
commit 8d6725eeb4
2 changed files with 9 additions and 9 deletions

View File

@@ -62,7 +62,7 @@ type payload struct {
}
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
if len(config) > 0 {
curConfig = *config[0]
@@ -84,16 +84,16 @@ func New(token, appKey, secret string, isProd bool, config ...*platformapi.APICo
return api
}
func (a *API) SetToken(newToken string) bool {
func (a *API) SetToken(newToken string) (retVal bool) {
curToken := a.GetToken()
if curToken != newToken {
a.locker.Lock()
defer a.locker.Unlock()
a.token = newToken
return true
retVal = true
baseapi.SugarLogger.Debugf("elm token changed from %v to %v", curToken, newToken)
}
return false
return retVal
}
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)
bodyStr := string(utils.MustMarshal(pl))
request := &http.Request{
Method: "POST",
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},
},
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) {
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
}
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)
if code == "EXCEED_LIMIT" {
return platformapi.ErrLevelExceedLimit, newErr

View File

@@ -20,14 +20,13 @@ func init() {
baseapi.Init(sugarLogger)
// sandbox
elmapi = New("f22acad55e8b11ae146ad9295e20cf4e", "RwT214gAsS", "56afff4b9ebd8a7eb532d18fa33f17be57f9b9db", false)
elmapi = New("7b642f1767b6ad5c074238f1bf4720f8", "RwT214gAsS", "56afff4b9ebd8a7eb532d18fa33f17be57f9b9db", false)
// prod
// elmapi = New("a530ade4a8e0b99542df0592b06575b5", "KLRDcOZGrk", "1fc221f8265506531da36fb613d5f5ad673f2e9a", true)
}
func TestTest(t *testing.T) {
q
sugarLogger.Debug(utils.GetCurTimeStr())
}