weldr: Allow cancel on waiting and running composes

Fix the cancel API to allow a waiting compose to be canceled.
This also fixes the cancel return code to be 400, the lorax-composer
behavior was a bug, and using 400 allows composer-cli to properly
display the error.
This commit is contained in:
Brian C. Lane 2022-01-25 14:29:47 -08:00 committed by Ondřej Budai
parent c877f14379
commit c657713181

View file

@ -2496,12 +2496,12 @@ func (api *API) composeCancelHandler(writer http.ResponseWriter, request *http.R
}
composeStatus := api.getComposeStatus(compose)
if composeStatus.State == ComposeWaiting {
if composeStatus.State != ComposeWaiting && composeStatus.State != ComposeRunning {
errors := responseError{
ID: "BuildInWrongState",
Msg: fmt.Sprintf("Build %s has not started yet. No logs to view.", uuidString),
Msg: fmt.Sprintf("Build %s is not in WAITING or RUNNING.", uuidString),
}
statusResponseError(writer, http.StatusOK, errors) // weirdly, Lorax returns 200 in this case
statusResponseError(writer, http.StatusBadRequest, errors)
return
}