Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make task not found error message for task protection endpoint consistent with Fargate #3748

Merged
merged 1 commit into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -330,15 +331,15 @@ 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)
if !found {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions agent/handlers/task_server_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
})
Expand Down Expand Up @@ -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",
},
},
}))
Expand Down