Skip to content

Commit

Permalink
fix(destination): delete users support add test-cases and better erro…
Browse files Browse the repository at this point in the history
…r strings (#2744)

* fix: oauth retry restricted to only one re-try attempt in case of refresh failure

* - add control-plane request timeout stat
- update error message to include actual response
- update naming
- making maxRetryAttempts as configurable
- include jobId in logs

* rename the attempts argument

* fix: info logs to debug deployment issue in dev

* Add logs

* revert logs

* revert to Debug logs

* insert logs for debugging

* fix: adding additional information into error responses, adding more unit-test cases

* fix: add nil check

* feat: add support for handling multiple responses from transformer & modify test-cases
- clarity in error message

* fix: remove extra-line

* fix: include refreshResponse nil check inside error status-code verification condition

Co-authored-by: Sai Sankeerth <sanpj2292@github.com>
  • Loading branch information
sanpj2292 and Sai Sankeerth committed Nov 30, 2022
1 parent e9b75e9 commit b69c4bb
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 44 deletions.
11 changes: 8 additions & 3 deletions regulation-worker/internal/delete/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (api *APIManager) deleteWithRetry(ctx context.Context, job model.Job, desti
}
err = setOAuthHeader(oAuthDetail.secretToken, req)
if err != nil {
pkgLogger.Errorf("[%v] error occurred while setting oauth header for workspace: %v, destination: %v", destination.Name, job.WorkspaceID, destination.DestinationID)
pkgLogger.Error(err)
return model.JobStatusFailed
}
Expand Down Expand Up @@ -198,7 +199,7 @@ func setOAuthHeader(secretToken *oauth.AuthResponse, req *http.Request) error {
func (api *APIManager) getOAuthDetail(destDetail *model.Destination, workspaceId string) (oauthDetail, error) {
id := oauth.GetAccountId(destDetail.Config, oauth.DeleteAccountIdKey)
if strings.TrimSpace(id) == "" {
return oauthDetail{}, fmt.Errorf("%v is not present for %v", oauth.DeleteAccountIdKey, destDetail.Name)
return oauthDetail{}, fmt.Errorf("[%v] Delete account ID key (%v) is not present for destination: %v", destDetail.Name, oauth.DeleteAccountIdKey, destDetail.DestinationID)
}
tokenStatusCode, secretToken := api.OAuth.FetchToken(&oauth.RefreshTokenParams{
AccountId: id,
Expand All @@ -223,9 +224,13 @@ func (api *APIManager) refreshOAuthToken(destName, workspaceId string, oAuthDeta
DestDefName: destName,
EventNamePrefix: "refresh_token",
}
statusCode, _ := api.OAuth.RefreshToken(refTokenParams)
statusCode, refreshResponse := api.OAuth.RefreshToken(refTokenParams)
if statusCode != http.StatusOK {
return fmt.Errorf("failed to refresh token for destination: %v", destName)
var refreshRespErr string
if refreshResponse != nil {
refreshRespErr = refreshResponse.Err
}
return fmt.Errorf("[%v] Failed to refresh token for destination in workspace(%v) & account(%v) with %v", destName, workspaceId, oAuthDetail.id, refreshRespErr)
}
return nil
}
Loading

0 comments on commit b69c4bb

Please sign in to comment.