packngo icon indicating copy to clipboard operation
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

Open t0mk opened this issue 6 years ago • 4 comments

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

t0mk avatar Dec 18 '18 14:12 t0mk

@patrickdevivo who should we assign this to?

jacobsmith928 avatar Feb 02 '19 19:02 jacobsmith928

@amenowanna for visibility. Seems like the API reporting an error incorrectly

patrickdevivo avatar Feb 04 '19 15:02 patrickdevivo

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.

t0mk avatar Feb 22 '19 14:02 t0mk

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"]

displague avatar Jul 22 '20 20:07 displague