@@ -52,9 +52,9 @@ type InvokeRequest struct {
52
52
53
53
type ErrorResponse struct {
54
54
ErrorMessage string `json:"errorMessage"`
55
- ErrorType string `json:"errorType"`
56
- RequestId string `json:"requestId"`
57
- StackTrace []string `json:"stackTrace"`
55
+ ErrorType string `json:"errorType,omitempty "`
56
+ RequestId string `json:"requestId,omitempty "`
57
+ StackTrace []string `json:"stackTrace,omitempty "`
58
58
}
59
59
60
60
func NewCustomInteropServer (lsOpts * LsOpts , delegate rapidcore.InteropServer , logCollector * LogCollector ) (server * CustomInteropServer ) {
@@ -99,12 +99,36 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
99
99
CorrelationID : "invokeCorrelationID" ,
100
100
NeedDebugLogs : true ,
101
101
InvokedFunctionArn : invokeR .InvokedFunctionArn ,
102
+ //DeadlineNs:
102
103
})
104
+ timeout := int (server .delegate .GetInvokeTimeout ().Seconds ())
105
+ isErr := false
103
106
if err != nil {
104
- log .Fatalln (err )
107
+ switch err {
108
+ case rapidcore .ErrInvokeTimeout :
109
+ log .Debugf ("Got invoke timeout" )
110
+ isErr = true
111
+ errorResponse := ErrorResponse {
112
+ ErrorMessage : fmt .Sprintf (
113
+ "%s %s Task timed out after %d.00 seconds" ,
114
+ time .Now ().Format ("2006-01-02T15:04:05Z" ),
115
+ invokeR .InvokeId ,
116
+ timeout ,
117
+ ),
118
+ }
119
+ jsonErrorResponse , err := json .Marshal (errorResponse )
120
+ if err != nil {
121
+ log .Fatalln ("unable to marshall json timeout response" )
122
+ }
123
+ _ , err = invokeResp .Write (jsonErrorResponse )
124
+ if err != nil {
125
+ log .Fatalln ("unable to write to response" )
126
+ }
127
+ default :
128
+ log .Fatalln (err )
129
+ }
105
130
}
106
- inv := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_TIMEOUT" )
107
- timeoutDuration , _ := time .ParseDuration (inv + "s" )
131
+ timeoutDuration := time .Duration (timeout ) * time .Second
108
132
memorySize := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" )
109
133
PrintEndReports (invokeR .InvokeId , "" , memorySize , invokeStart , timeoutDuration , logCollector )
110
134
@@ -117,8 +141,7 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
117
141
var errR map [string ]any
118
142
marshalErr := json .Unmarshal (invokeResp .Body , & errR )
119
143
120
- isErr := false
121
- if marshalErr == nil {
144
+ if ! isErr && marshalErr == nil {
122
145
_ , isErr = errR ["errorType" ]
123
146
}
124
147
0 commit comments