packngo
packngo copied to clipboard
API wrongly reports `Facility can't be blank` when device plan is unavailable, and when facility list doesn't contains a valid facility slug
When creating device over the API, and passing more than one facility (for failover), if a desired plan is not available in either of the facilities, the API responses with HTTP 422 Facility can't be blank
.
It should rather be Plan xyz is not available in either of given facilities
.
example request and response:
=======[REQUEST]=============
POST /projects/1c6d4d44-5d27-4ec7-8ec0-5cf6ac32cf5b/devices HTTP/1.1
{"hostname":"GIlqJoEP","plan":"baremetal_0",
"facility":["hkg1","sin1"],"operating_system":"alpine_3",
"billing_cycle":"hourly",
"project_id":"1c6d4d44-5d27-4ec7-8ec0-5cf6ac32cf5b","userdata":"","tags":null}
2018/12/18 15:58:22
=======[RESPONSE]============
HTTP/2.0 422 Unprocessable Entity
{"errors":["Facility can't be blank"]}
This is a cause of #120
@patrickdevivo who should we assign this to?
@amenowanna for visibility. Seems like the API reporting an error incorrectly
This also happens when users pass invalid values in the facilities argument. API seems to go all through the list and when not a signle item makes sense, it reports "Facility can't be blank", which is misleading.
While trying to reproduce this, I encountered somewhat similar, when passing multiple facilities and one is incorrect (nyc5 instead of ny5 in this case):
{"errors":["[\"ewr1\", \"nyc5\"] is not a valid facility"]}
I get the same error with multiple made-up facility names (seems like a change since @t0mk's finding https://github.com/packethost/packngo/issues/121#issuecomment-466417150):
{"errors":["[\"nyc5\", \"bewr1\"] is not a valid facility"]}
I did not encounter any provisioning problems when using the correct parameter and available facilities: "facility": ["ny5","ewr1"]