Skip to content

Commit

Permalink
fix differentiation between error and non-error (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikschubert authored Sep 28, 2022
1 parent 08b4cf7 commit f822661
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
go-version: 1.18

- name: Build
run: make compile-lambda-linux-all
Expand Down
21 changes: 13 additions & 8 deletions cmd/localstack/custom_interop.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
NeedDebugLogs: true,
InvokedFunctionArn: invokeR.InvokedFunctionArn,
})
if err != nil {
log.Fatalln(err)
}
inv := GetEnvOrDie("AWS_LAMBDA_FUNCTION_TIMEOUT")
timeoutDuration, _ := time.ParseDuration(inv + "s")
memorySize := GetEnvOrDie("AWS_LAMBDA_FUNCTION_MEMORY_SIZE")
Expand All @@ -111,21 +114,23 @@ func NewCustomInteropServer(lsOpts *LsOpts, delegate rapidcore.InteropServer, lo
// TODO: handle err
}

callErr := false
var errR ErrorResponse
err := json.Unmarshal(invokeResp.Body, &errR)
if err == nil {
callErr = true
} else {
log.Error(err)
var errR map[string]any
marshalErr := json.Unmarshal(invokeResp.Body, &errR)

if marshalErr != nil {
log.Fatalln(marshalErr)
}

if callErr {
_, isErr := errR["errorType"]

if isErr {
log.Infoln("Sending to /error")
_, err = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/error", "application/json", bytes.NewReader(invokeResp.Body))
if err != nil {
log.Error(err)
}
} else {
log.Infoln("Sending to /response")
_, err = http.Post(server.upstreamEndpoint+"/invocations/"+invokeR.InvokeId+"/response", "application/json", bytes.NewReader(invokeResp.Body))
if err != nil {
log.Error(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/localstack/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {
go sandbox.Create()

// start runtime init
go InitHandler(sandbox, "$LATEST", 30) // TODO: replace this with a custom init
go InitHandler(sandbox, GetEnvOrDie("AWS_LAMBDA_FUNCTION_VERSION"), 30) // TODO: replace this with a custom init

// TODO: make the tracing server optional
// start blocking with the tracing server
Expand Down

0 comments on commit f822661

Please sign in to comment.