You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ab...@apache.org on 2023/05/24 06:25:40 UTC

[incubator-devlake] branch release-v0.17 updated: fix: finish collect event when http code=422 (#5241)

This is an automated email from the ASF dual-hosted git repository.

abeizn pushed a commit to branch release-v0.17
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v0.17 by this push:
     new 88edcbe25 fix: finish collect event when http code=422 (#5241)
88edcbe25 is described below

commit 88edcbe25b4a2140d95c37e941202a86a4f2ffb1
Author: Likyh <ya...@meri.co>
AuthorDate: Fri May 19 20:10:16 2023 +0800

    fix: finish collect event when http code=422 (#5241)
---
 backend/helpers/pluginhelper/api/api_async_client.go | 11 ++++++-----
 backend/helpers/pluginhelper/api/api_collector.go    |  2 +-
 backend/plugins/github/tasks/api_client.go           |  7 +++++++
 backend/plugins/github/tasks/event_collector.go      |  2 ++
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/backend/helpers/pluginhelper/api/api_async_client.go b/backend/helpers/pluginhelper/api/api_async_client.go
index 715245d64..2c746988f 100644
--- a/backend/helpers/pluginhelper/api/api_async_client.go
+++ b/backend/helpers/pluginhelper/api/api_async_client.go
@@ -163,6 +163,12 @@ func (apiClient *ApiAsyncClient) DoAsync(
 
 		apiClient.logger.Debug("endpoint: %s  method: %s  header: %s  body: %s query: %s", path, method, header, body, query)
 		res, err = apiClient.Do(method, path, query, body, header)
+		if err == ErrIgnoreAndContinue {
+			// make sure defer func got be executed
+			err = nil //nolint
+			return nil
+		}
+
 		// make sure response body is read successfully, or we might have to retry
 		if err == nil {
 			// make sure response.Body stream will be closed to avoid running out of file handle
@@ -173,11 +179,6 @@ func (apiClient *ApiAsyncClient) DoAsync(
 				res.Body = io.NopCloser(bytes.NewBuffer(respBody))
 			}
 		}
-		if err == ErrIgnoreAndContinue {
-			// make sure defer func got be executed
-			err = nil //nolint
-			return nil
-		}
 
 		// check
 		needRetry := false
diff --git a/backend/helpers/pluginhelper/api/api_collector.go b/backend/helpers/pluginhelper/api/api_collector.go
index 845658bef..6a6667879 100644
--- a/backend/helpers/pluginhelper/api/api_collector.go
+++ b/backend/helpers/pluginhelper/api/api_collector.go
@@ -127,7 +127,7 @@ func NewApiCollector(args ApiCollectorArgs) (*ApiCollector, errors.Error) {
 		apiCollector.SetAfterResponse(args.AfterResponse)
 	} else {
 		apiCollector.SetAfterResponse(func(res *http.Response) errors.Error {
-			if res.StatusCode == http.StatusUnauthorized || res.StatusCode == http.StatusUnprocessableEntity {
+			if res.StatusCode == http.StatusUnauthorized {
 				return errors.Unauthorized.New("authentication failed, please check your AccessToken")
 			}
 			return nil
diff --git a/backend/plugins/github/tasks/api_client.go b/backend/plugins/github/tasks/api_client.go
index c9bfa852c..3e1440e71 100644
--- a/backend/plugins/github/tasks/api_client.go
+++ b/backend/plugins/github/tasks/api_client.go
@@ -83,3 +83,10 @@ func CreateApiClient(taskCtx plugin.TaskContext, connection *models.GithubConnec
 	}
 	return asyncApiClient, nil
 }
+
+func ignoreHTTPStatus422(res *http.Response) errors.Error {
+	if res.StatusCode == http.StatusUnprocessableEntity {
+		return api.ErrIgnoreAndContinue
+	}
+	return nil
+}
diff --git a/backend/plugins/github/tasks/event_collector.go b/backend/plugins/github/tasks/event_collector.go
index f1f6831c5..da15a98de 100644
--- a/backend/plugins/github/tasks/event_collector.go
+++ b/backend/plugins/github/tasks/event_collector.go
@@ -83,6 +83,7 @@ func CollectApiEvents(taskCtx plugin.SubTaskContext) errors.Error {
 					}
 					return items, nil
 				},
+				AfterResponse: ignoreHTTPStatus422,
 			},
 			GetCreated: func(item json.RawMessage) (time.Time, errors.Error) {
 				e := &SimpleGithubApiEvents{}
@@ -118,6 +119,7 @@ func CollectApiEvents(taskCtx plugin.SubTaskContext) errors.Error {
 					res.Body.Close()
 					return []json.RawMessage{body}, nil
 				},
+				AfterResponse: ignoreHTTPStatus422,
 			},
 		},
 	})