From 3059857f52cbda8eee80856968cf40f39584d0b8 Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Tue, 20 Feb 2024 14:42:37 -0600 Subject: [PATCH] Handle the situation where we pass a single host to inventory and it responds with a 404 --- internal/api/connectors/inventory/inventory.go | 6 +++++- .../api/controllers/private/highlevelConnectionStatus.go | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/api/connectors/inventory/inventory.go b/internal/api/connectors/inventory/inventory.go index 3a186717..018acaad 100644 --- a/internal/api/connectors/inventory/inventory.go +++ b/internal/api/connectors/inventory/inventory.go @@ -142,6 +142,10 @@ func (this *inventoryConnectorImpl) getHostDetails( return nil, err } + if response.StatusCode() == http.StatusNotFound { + return []HostOut{}, nil + } + if response.JSON200 == nil { return nil, utils.UnexpectedResponse(response.HTTPResponse) } @@ -184,7 +188,7 @@ func (this *inventoryConnectorImpl) GetHostConnectionDetails(ctx context.Context } if len(hostResults) == 0 { - return nil, nil + return []HostDetails{}, nil } systemProfileResults, err := this.getSystemProfileDetails(ctx, IDs, order_by, order_how, limit, offset) diff --git a/internal/api/controllers/private/highlevelConnectionStatus.go b/internal/api/controllers/private/highlevelConnectionStatus.go index 7e95555a..dbe66630 100644 --- a/internal/api/controllers/private/highlevelConnectionStatus.go +++ b/internal/api/controllers/private/highlevelConnectionStatus.go @@ -49,6 +49,13 @@ func (this *controllers) ApiInternalHighlevelConnectionStatus(ctx echo.Context) return ctx.NoContent(http.StatusBadRequest) } + if len(hostConnectorDetails) == 0 { + // FIXME: I'm not sure that this is right. Basically, we need to return a response that says the host was not available.... + // This could happen if the host was deleted from inventory or an error (404) came back from inventory + // Think through this a bit more and build a test around this at the API level + return ctx.JSON(http.StatusOK, noRHCResponses) + } + satellite, directConnected, noRhc := sortHostsByRecipient(hostConnectorDetails) // Return noRHC If no Satellite or Direct Connected hosts exist