From 71b103a7c12a6844d92d5446a0d82c86de42abb1 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 19 Oct 2021 11:46:19 +0200 Subject: [PATCH] improve error handling in case AMQP session is not available --- .../ic_amqpmethods.go | 32 +++++++++++++------ routes/user/scenario_duplication.go | 12 ++++--- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/routes/infrastructure-component/ic_amqpmethods.go b/routes/infrastructure-component/ic_amqpmethods.go index 954ad84..34edb21 100644 --- a/routes/infrastructure-component/ic_amqpmethods.go +++ b/routes/infrastructure-component/ic_amqpmethods.go @@ -168,11 +168,7 @@ func createExternalIC(payload ICUpdate, ICUUID string, body []byte) error { log.Println("AMQP: Created IC with UUID ", newIC.UUID) // send ping to get full status update of this IC - if session != nil { - err = SendPing(ICUUID) - } else { - err = fmt.Errorf("cannot sent ping to %v because AMQP session is nil", ICUUID) - } + err = SendPing(ICUUID) return err } @@ -257,8 +253,17 @@ func SendPing(uuid string) error { return err } - err = session.Send(payload, uuid) - return err + if session != nil { + if session.IsReady { + err = session.Send(payload, uuid) + return err + } else { + return fmt.Errorf("could not send ping, AMQP session not ready") + } + } else { + return fmt.Errorf("could not send ping, AMQP session is nil") + } + } func sendActionAMQP(action Action, destinationUUID string) error { @@ -268,6 +273,15 @@ func sendActionAMQP(action Action, destinationUUID string) error { return err } - err = session.Send(payload, destinationUUID) - return err + if session != nil { + if session.IsReady { + err = session.Send(payload, destinationUUID) + return err + } else { + return fmt.Errorf("could not send action, AMQP session is not ready") + } + } else { + return fmt.Errorf("could not send action, AMQP session is nil") + } + } diff --git a/routes/user/scenario_duplication.go b/routes/user/scenario_duplication.go index 7b0b4a4..c5c6910 100644 --- a/routes/user/scenario_duplication.go +++ b/routes/user/scenario_duplication.go @@ -485,11 +485,15 @@ func duplicateIC(ic database.InfrastructureComponent, userName string) (string, return "", err } - if session.IsReady { - err = session.Send(payload, ic.Manager) - return newUUID, err + if session != nil { + if session.IsReady { + err = session.Send(payload, ic.Manager) + return newUUID, err + } else { + return "", fmt.Errorf("could not send IC create action, AMQP session is not ready") + } } else { - return "", fmt.Errorf("could not send IC create action, AMQP session is not ready") + return "", fmt.Errorf("could not send IC create action, AMQP session is nil") } }