Respond with 404 when instance not found 43/142643/4
authorFiete Ostkamp <fiete.ostkamp@telekom.de>
Thu, 4 Dec 2025 15:40:28 +0000 (16:40 +0100)
committerFiete Ostkamp <fiete.ostkamp@telekom.de>
Thu, 12 Mar 2026 06:42:13 +0000 (07:42 +0100)
- respond with 404 not found on /instance/{instID} endpoint
- this replaces a 500 internal error response which is misleading

Issue-ID: MULTICLOUD-1526
Change-Id: Ibbe49cbb3c1286546f7dd1d9c24834291b14d9be
Signed-off-by: Fiete Ostkamp <fiete.ostkamp@telekom.de>
src/k8splugin/api/instancehandler.go
src/k8splugin/api/instancehandler_test.go

index b5ef6d3..5ce52f2 100644 (file)
@@ -186,6 +186,10 @@ func (i instanceHandler) getHandler(w http.ResponseWriter, r *http.Request) {
        }
 
        if err != nil {
+               if err.Error() == "Get Instance: Error finding master table: mongo: no documents in result" {
+                       http.Error(w, err.Error(), http.StatusNotFound)
+                       return
+               }
                log.Error("Error getting Instance", log.Fields{
                        "error": err,
                        "id":    id,
index f1ef880..37b307c 100644 (file)
@@ -242,7 +242,15 @@ func TestInstanceGetHandler(t *testing.T) {
                        },
                },
                {
-                       label:        "Succesful get an Instance",
+                       label:        "Not found Instance",
+                       input:        "HaKpys8e",
+                       expectedCode: http.StatusNotFound,
+                       instClient: &mockInstanceClient{
+                               err: pkgerrors.New("Get Instance: Error finding master table: mongo: no documents in result"),
+                       },
+               },
+               {
+                       label:        "Successful get an Instance",
                        input:        "HaKpys8e",
                        expectedCode: http.StatusOK,
                        expectedResponse: &app.InstanceResponse{