From e91b1bfa474963a972b090eaaa1ddf2b5178e807 Mon Sep 17 00:00:00 2001 From: Amogh Rathore Date: Mon, 12 Jun 2023 16:41:51 +0000 Subject: [PATCH] Make task not found error message consistent for task protection endpoint --- .../handlers/agentapi/taskprotection/v1/handlers/handlers.go | 5 +++-- .../agentapi/taskprotection/v1/handlers/handlers_test.go | 4 ++-- agent/handlers/task_server_setup_test.go | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/agent/handlers/agentapi/taskprotection/v1/handlers/handlers.go b/agent/handlers/agentapi/taskprotection/v1/handlers/handlers.go index 7bcce84f771..3dccfdc7c48 100644 --- a/agent/handlers/agentapi/taskprotection/v1/handlers/handlers.go +++ b/agent/handlers/agentapi/taskprotection/v1/handlers/handlers.go @@ -47,6 +47,7 @@ const ( // must be lower than server write timeout ecsCallTimeout = 4 * time.Second ecsCallTimedOutError = "Timed out calling ECS Task Protection API" + taskNotFoundErrorMsg = "Failed to find a task for the request" ) // TaskProtectionPath Returns endpoint path for UpdateTaskProtection API @@ -330,7 +331,7 @@ func getTaskFromRequest(state dockerstate.TaskEngineState, r *http.Request) (*ap logger.Error("Failed to find task ARN for task protection request", logger.Fields{ loggerfield.Error: err, }) - return nil, http.StatusNotFound, ecs.ErrCodeResourceNotFoundException, errors.New("Invalid request: no task was found") + return nil, http.StatusNotFound, ecs.ErrCodeResourceNotFoundException, errors.New(taskNotFoundErrorMsg) } task, found := state.TaskByArn(taskARN) @@ -338,7 +339,7 @@ func getTaskFromRequest(state dockerstate.TaskEngineState, r *http.Request) (*ap logger.Critical("No task was found for taskARN for task protection request", logger.Fields{ loggerfield.TaskARN: taskARN, }) - return nil, http.StatusInternalServerError, ecs.ErrCodeServerException, errors.New("Failed to find a task for the request") + return nil, http.StatusInternalServerError, ecs.ErrCodeServerException, errors.New(taskNotFoundErrorMsg) } return task, http.StatusOK, "", nil diff --git a/agent/handlers/agentapi/taskprotection/v1/handlers/handlers_test.go b/agent/handlers/agentapi/taskprotection/v1/handlers/handlers_test.go index f57d34a8c64..b8aeecb6cb5 100644 --- a/agent/handlers/agentapi/taskprotection/v1/handlers/handlers_test.go +++ b/agent/handlers/agentapi/taskprotection/v1/handlers/handlers_test.go @@ -190,7 +190,7 @@ func TestUpdateTaskProtectionHandlerTaskARNNotFound(t *testing.T) { expectedResponse := types.TaskProtectionResponse{ Error: &types.ErrorResponse{ Code: ecs.ErrCodeResourceNotFoundException, - Message: "Invalid request: no task was found", + Message: "Failed to find a task for the request", }, } testUpdateTaskProtectionHandler(t, mockState, testV3EndpointId, nil, nil, request, @@ -456,7 +456,7 @@ func TestGetTaskProtectionHandlerTaskARNNotFound(t *testing.T) { expectedResponse := types.TaskProtectionResponse{ Error: &types.ErrorResponse{ Code: ecs.ErrCodeResourceNotFoundException, - Message: "Invalid request: no task was found", + Message: "Failed to find a task for the request", }, } testGetTaskProtectionHandler(t, mockState, testV3EndpointId, nil, nil, diff --git a/agent/handlers/task_server_setup_test.go b/agent/handlers/task_server_setup_test.go index 4d285047177..97e1c1ce0f5 100644 --- a/agent/handlers/task_server_setup_test.go +++ b/agent/handlers/task_server_setup_test.go @@ -2810,7 +2810,7 @@ func TestGetTaskProtection(t *testing.T) { expectedResponseBody: agentapi.TaskProtectionResponse{ Error: &agentapi.ErrorResponse{ Code: ecs.ErrCodeResourceNotFoundException, - Message: "Invalid request: no task was found", + Message: "Failed to find a task for the request", }, }, }) @@ -3058,7 +3058,7 @@ func TestUpdateTaskProtection(t *testing.T) { expectedResponseBody: agentapi.TaskProtectionResponse{ Error: &agentapi.ErrorResponse{ Code: ecs.ErrCodeResourceNotFoundException, - Message: "Invalid request: no task was found", + Message: "Failed to find a task for the request", }, }, }))