weldr: Fix blueprints/depsolve response
The response always returns a 200 with a JSON response. Any errors will be in the errors list.
This commit is contained in:
parent
e13ebd46ee
commit
e3d1a34ab6
2 changed files with 12 additions and 8 deletions
|
|
@ -828,6 +828,7 @@ func (api *API) blueprintsDepsolveHandler(writer http.ResponseWriter, request *h
|
|||
}
|
||||
|
||||
blueprints := []entry{}
|
||||
blueprintsErrors := []responseError{}
|
||||
for i, name := range names {
|
||||
// remove leading / from first name
|
||||
if i == 0 {
|
||||
|
|
@ -835,12 +836,11 @@ func (api *API) blueprintsDepsolveHandler(writer http.ResponseWriter, request *h
|
|||
}
|
||||
blueprint, _ := api.store.GetBlueprint(name)
|
||||
if blueprint == nil {
|
||||
errors := responseError{
|
||||
blueprintsErrors = append(blueprintsErrors, responseError{
|
||||
ID: "UnknownBlueprint",
|
||||
Msg: fmt.Sprintf("%s: blueprint not found", name),
|
||||
}
|
||||
statusResponseError(writer, http.StatusBadRequest, errors)
|
||||
return
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
dependencies, _, _, err := api.depsolveBlueprint(blueprint, "", api.arch, false)
|
||||
|
|
@ -859,7 +859,7 @@ func (api *API) blueprintsDepsolveHandler(writer http.ResponseWriter, request *h
|
|||
|
||||
err := json.NewEncoder(writer).Encode(reply{
|
||||
Blueprints: blueprints,
|
||||
Errors: []responseError{},
|
||||
Errors: blueprintsErrors,
|
||||
})
|
||||
common.PanicOnError(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1366,13 +1366,17 @@ func (c *checkBlueprintsV0) CheckBlueprintDepsolveV0() bool {
|
|||
func (c *checkBlueprintsV0) CheckNonBlueprintDepsolveV0() bool {
|
||||
name := "Depsolve a non-existent blueprint"
|
||||
|
||||
_, api, err := client.DepsolveBlueprintV0(c.socket, "test-deps-non-blueprint-v0")
|
||||
resp, api, err := client.DepsolveBlueprintV0(c.socket, "test-deps-non-blueprint-v0")
|
||||
if err != nil {
|
||||
log.Printf("FAIL: %s failed: %s", name, err.Error())
|
||||
return false
|
||||
}
|
||||
if api == nil || api.Status {
|
||||
log.Printf("FAIL: %s failed to return an error", name)
|
||||
if api != nil {
|
||||
log.Printf("FAIL: %s failed: %s", name, api)
|
||||
return false
|
||||
}
|
||||
if len(resp.Errors) == 0 {
|
||||
log.Printf("FAIL: %s failed with no error: %v", name, resp)
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue