improve error handling in case AMQP session is not available

This commit is contained in:
Sonja Happ 2021-10-19 11:46:19 +02:00
parent 9af822b801
commit 71b103a7c1
2 changed files with 31 additions and 13 deletions

View file

@ -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")
}
}

View file

@ -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")
}
}