Skip to content

Commit

Permalink
Add some more logging in http executor
Browse files Browse the repository at this point in the history
  • Loading branch information
radito3 committed Apr 18, 2024
1 parent 57920b1 commit 85aedfb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions internal/executors/http/http_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func (e *HttpRequestExecutor) Execute(ctx executors.Context) *executors.Executor
// TODO: add more logging
switch typedErr := err.(type) {
case *executors.RetryableError:
// TODO: test on dev as the Delay service crashes localdev
return executors.NewExecutorResult(
executors.Status(pb.TaskExecutionResponseMessage_TASK_STATE_FAILED_RETRYABLE),
executors.Error(typedErr),
Expand Down Expand Up @@ -108,18 +109,21 @@ func execute(c *http.Client, p *HttpRequestParameters, authHeader string) (*Http
log.Printf("Executing request %s %s...\n", p.method, p.url)
resp, err := c.Do(req)
if requestTimedOut(err) {
log.Println("Request timed out...")
if p.succeedOnTimeout {
log.Println("SucceedOnTimeout has been configured. Returning successful response...")
return newTimedOutHttpResponse(req, resp)
}

return nil, executors.NewRetryableError("HTTP request timed out after %d seconds", p.timeout).WithCause(err)
}

if err != nil {
return nil, executors.NewNonRetryableError("Error occurred while trying to execute actual HTTP request: %v", err).WithCause(err)
return nil, executors.NewNonRetryableError("Error occurred while executing HTTP request: %v", err).WithCause(err)
}
defer resp.Body.Close()

log.Println("Reading response body...")
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, executors.NewNonRetryableError("Error occurred while trying to read HTTP response body: %v", err).WithCause(err)
Expand All @@ -136,9 +140,9 @@ func execute(c *http.Client, p *HttpRequestParameters, authHeader string) (*Http
Time(<-timeCh),
)
if err != nil {
log.Println("Could not build response object:", err)
return nil, executors.NewNonRetryableError("Error occurred while trying to build HTTP response: %v", err).WithCause(err)
}

return r, nil
}

Expand Down

0 comments on commit 85aedfb

Please sign in to comment.