@@ -32,6 +32,7 @@ func (e *HttpRequestExecutor) Execute(ctx executors.Context) *executors.Executor
32
32
log .Println ("Executing HttpRequest command..." )
33
33
params , err := NewHttpRequestParametersFromContext (ctx )
34
34
if err != nil {
35
+ log .Println ("Could not create HTTP request params: returning Task state Failed Non-Retryable Error with:" , err )
35
36
return executors .NewExecutorResult (
36
37
executors .Status (pb .TaskExecutionResponseMessage_TASK_STATE_FAILED_NON_RETRYABLE ),
37
38
executors .Error (err ),
@@ -42,25 +43,29 @@ func (e *HttpRequestExecutor) Execute(ctx executors.Context) *executors.Executor
42
43
43
44
switch typedErr := err .(type ) {
44
45
case * executors.RetryableError :
46
+ log .Println ("Returning Task state Failed Retryable Error..." )
45
47
return executors .NewExecutorResult (
46
48
executors .Status (pb .TaskExecutionResponseMessage_TASK_STATE_FAILED_RETRYABLE ),
47
49
executors .Error (typedErr ),
48
50
)
49
51
case * executors.NonRetryableError :
52
+ log .Println ("Returning Task state Failed Non-Retryable Error..." )
50
53
return executors .NewExecutorResult (
51
54
executors .Status (pb .TaskExecutionResponseMessage_TASK_STATE_FAILED_NON_RETRYABLE ),
52
55
executors .Error (typedErr ),
53
56
)
54
57
default :
55
58
m := resp .ToMap ()
56
59
if ! resp .successful {
60
+ log .Println ("Returning Task state Failed Retryable Error from HTTP response..." )
57
61
return executors .NewExecutorResult (
58
62
executors .Output (m ),
59
63
executors .Status (pb .TaskExecutionResponseMessage_TASK_STATE_FAILED_RETRYABLE ),
60
64
executors .ErrorString (buildHttpError (resp )),
61
65
)
62
66
}
63
67
68
+ log .Println ("Returning Task state Completed..." )
64
69
return executors .NewExecutorResult (
65
70
executors .Output (m ),
66
71
executors .Status (pb .TaskExecutionResponseMessage_TASK_STATE_COMPLETED ),
@@ -104,26 +109,34 @@ func execute(c *http.Client, p *HttpRequestParameters, authHeader string) (*Http
104
109
return nil , executors .NewNonRetryableError ("could not create http request: %v" , err ).WithCause (err )
105
110
}
106
111
107
- log .Printf ("Executing request %s %s...\n " , p .method , p .url )
112
+ log .Printf ("HTTP Client: executing request %s %s...\n " , p .method , p .url )
108
113
resp , err := c .Do (req )
109
114
if requestTimedOut (err ) {
115
+ log .Println ("HTTP Client: request timed out after" , p .timeout , "seconds" )
110
116
if p .succeedOnTimeout {
117
+ log .Println ("HTTP Client: SucceedOnTimeout has been configured. Returning successful response..." )
111
118
return newTimedOutHttpResponse (req , resp )
112
119
}
113
120
114
121
return nil , executors .NewRetryableError ("HTTP request timed out after %d seconds" , p .timeout ).WithCause (err )
115
122
}
116
123
117
124
if err != nil {
118
- return nil , executors .NewNonRetryableError ("Error occurred while trying to execute actual HTTP request: %v" , err ).WithCause (err )
125
+ log .Println ("HTTP Client: error occurred while executing request:" , err )
126
+ return nil , executors .NewNonRetryableError ("Error occurred while executing HTTP request: %v" , err ).WithCause (err )
119
127
}
120
128
defer resp .Body .Close ()
121
129
130
+ log .Println ("HTTP Client: received response:" , resp .Status )
131
+
132
+ log .Println ("HTTP Client: reading response body..." )
122
133
body , err := io .ReadAll (resp .Body )
123
134
if err != nil {
135
+ log .Println ("HTTP Client: error reading response body:" , err )
124
136
return nil , executors .NewNonRetryableError ("Error occurred while trying to read HTTP response body: %v" , err ).WithCause (err )
125
137
}
126
138
139
+ log .Println ("HTTP Client: building response object..." )
127
140
r , err := NewHttpResponse (
128
141
Url (req .URL .String ()),
129
142
Method (req .Method ),
@@ -135,9 +148,9 @@ func execute(c *http.Client, p *HttpRequestParameters, authHeader string) (*Http
135
148
Time (<- timeCh ),
136
149
)
137
150
if err != nil {
151
+ log .Println ("HTTP Client: could not build response object:" , err )
138
152
return nil , executors .NewNonRetryableError ("Error occurred while trying to build HTTP response: %v" , err ).WithCause (err )
139
153
}
140
-
141
154
return r , nil
142
155
}
143
156
@@ -147,10 +160,12 @@ func requestTimedOut(err error) bool {
147
160
}
148
161
149
162
func createRequest (method string , url string , headers map [string ]string , body , authHeader string ) (* http.Request , <- chan int64 , error ) {
163
+ log .Println ("HTTP Client: creating request:" , method , url )
150
164
timeCh := make (chan int64 , 1 )
151
165
152
166
req , err := http .NewRequest (method , url , strings .NewReader (body ))
153
167
if err != nil {
168
+ log .Println ("HTTP Client: error creating request:" , err )
154
169
return nil , nil , err
155
170
}
156
171
addHeaders (req , headers , authHeader )
0 commit comments