This is an automated email from the ASF dual-hosted git repository.
abeizn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 3ccc8c07e fix: finish collect event when http code=422 (#5241)
3ccc8c07e is described below
commit 3ccc8c07e6c5da1d6021ec2498d15308d7e49b9a
Author: Likyh <[email protected]>
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 051008e3a..0a0b15bc9 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,
},
},
})