equinixmetal-archive / packngo

[Deprecated] A Golang client for the Equinix Metal API. (Packet is now Equinix Metal)
https://deploy.equinix.com/labs/equinix-sdk-go/
Other
79 stars 53 forks source link

feat: add error handling for application/problem+json responses #367

Open displague opened 1 year ago

displague commented 1 year ago

While the Equinix Metal API does not return this API header natively, tools such as Spotlight Prism can proxy the API and they may return this standard error content-type.

https://datatracker.ietf.org/doc/html/rfc7807

How has this been tested?

As demonstrated in https://gist.github.com/displague/27363182851f0eab4b599401f83f4b1e, errors returned with this content type are passed through as a JSON blob.

{"type":"https://stoplight.io/prism/errors#VIOLATIONS","title":"Request/Response not valid","status":500,"detail":"Your request/response is not valid and the --errors flag is set, so Prism is generating this error for you.","validation":[{"location":["response","body","plans","0","type"],"severity":"Error","code":"type","message":"Request body property plans.0.type must be string"},{"location":["response","body","plans","0","type"],"severity":"Error","code":"enum","message":"Request body property plans.0.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","1","specs","drives","1","type"],"severity":"Error","code":"enum","message":"Request body property plans.1.specs.drives.1.type must be equal to one of the allowed values: HDD, SSD, NVME"},{"location":["response","body","plans","1","type"],"severity":"Error","code":"type","message":"Request body property plans.1.type must be string"},{"location":["response","body","plans","1","type"],"severity":"Error","code":"enum","message":"Request body property plans.1.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","2","specs","drives","1","type"],"severity":"Error","code":"enum","message":"Request body property plans.2.specs.drives.1.type must be equal to one of the allowed values: HDD, SSD, NVME"},{"location":["response","body","plans","11","specs","drives","1","type"],"severity":"Error","code":"enum","message":"Request body property plans.11.specs.drives.1.type must be equal to one of the allowed values: HDD, SSD, NVME"},{"location":["response","body","plans","23","type"],"severity":"Error","code":"type","message":"Request body property plans.23.type must be string"},{"location":["response","body","plans","23","type"],"severity":"Error","code":"enum","message":"Request body property plans.23.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","24","type"],"severity":"Error","code":"type","message":"Request body property plans.24.type must be string"},{"location":["response","body","plans","24","type"],"severity":"Error","code":"enum","message":"Request body property plans.24.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","25","type"],"severity":"Error","code":"type","message":"Request body property plans.25.type must be string"},{"location":["response","body","plans","25","type"],"severity":"Error","code":"enum","message":"Request body property plans.25.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","26","type"],"severity":"Error","code":"type","message":"Request body property plans.26.type must be string"},{"location":["response","body","plans","26","type"],"severity":"Error","code":"enum","message":"Request body property plans.26.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","28","specs","drives","0","type"],"severity":"Error","code":"enum","message":"Request body property plans.28.specs.drives.0.type must be equal to one of the allowed values: HDD, SSD, NVME"},{"location":["response","body","plans","28","specs","nics","0","type"],"severity":"Error","code":"enum","message":"Request body property plans.28.specs.nics.0.type must be equal to one of the allowed values: 1Gbps, 10Gbps, 25Gbps"},{"location":["response","body","plans","29","specs","drives","0","type"],"severity":"Error","code":"enum","message":"Request body property plans.29.specs.drives.0.type must be equal to one of the allowed values: HDD, SSD, NVME"},{"location":["response","body","plans","29","specs","nics","0","type"],"severity":"Error","code":"enum","message":"Request body property plans.29.specs.nics.0.type must be equal to one of the allowed values: 1Gbps, 10Gbps, 25Gbps"},{"location":["response","body","plans","42","type"],"severity":"Error","code":"type","message":"Request body property plans.42.type must be string"},{"location":["response","body","plans","42","type"],"severity":"Error","code":"enum","message":"Request body property plans.42.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","43","specs","drives","1","type"],"severity":"Error","code":"enum","message":"Request body property plans.43.specs.drives.1.type must be equal to one of the allowed values: HDD, SSD, NVME"},{"location":["response","body","plans","43","type"],"severity":"Error","code":"type","message":"Request body property plans.43.type must be string"},{"location":["response","body","plans","43","type"],"severity":"Error","code":"enum","message":"Request body property plans.43.type must be equal to one of the allowed values: standard, workload_optimized, custom"},{"location":["response","body","plans","44","specs","drives","1","type"],"severity":"Error","code":"enum","message":"Request body property plans.44.specs.drives.1.type must be equal to one of the allowed values: HDD, SSD, NVME"}]}