@@ -52,9 +52,9 @@ type InvokeRequest struct {
5252
5353type ErrorResponse struct {
5454 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 "`
5858}
5959
6060func NewCustomInteropServer (lsOpts * LsOpts , delegate rapidcore.InteropServer , logCollector * LogCollector ) (server * CustomInteropServer ) {
@@ -99,12 +99,36 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
9999 CorrelationID : "invokeCorrelationID" ,
100100 NeedDebugLogs : true ,
101101 InvokedFunctionArn : invokeR .InvokedFunctionArn ,
102+ //DeadlineNs:
102103 })
104+ timeout := int (server .delegate .GetInvokeTimeout ().Seconds ())
105+ isErr := false
103106 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+ }
105130 }
106- inv := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_TIMEOUT" )
107- timeoutDuration , _ := time .ParseDuration (inv + "s" )
131+ timeoutDuration := time .Duration (timeout ) * time .Second
108132 memorySize := GetEnvOrDie ("AWS_LAMBDA_FUNCTION_MEMORY_SIZE" )
109133 PrintEndReports (invokeR .InvokeId , "" , memorySize , invokeStart , timeoutDuration , logCollector )
110134
@@ -117,8 +141,7 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
117141 var errR map [string ]any
118142 marshalErr := json .Unmarshal (invokeResp .Body , & errR )
119143
120- isErr := false
121- if marshalErr == nil {
144+ if ! isErr && marshalErr == nil {
122145 _ , isErr = errR ["errorType" ]
123146 }
124147
0 commit comments