github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/packet/errors.go (about) 1 package packet 2 3 import ( 4 "net/http" 5 "strings" 6 7 "github.com/packethost/packngo" 8 ) 9 10 func friendlyError(err error) error { 11 if e, ok := err.(*packngo.ErrorResponse); ok { 12 return &ErrorResponse{ 13 StatusCode: e.Response.StatusCode, 14 Errors: Errors(e.Errors), 15 } 16 } 17 return err 18 } 19 20 func isForbidden(err error) bool { 21 if r, ok := err.(*ErrorResponse); ok { 22 return r.StatusCode == http.StatusForbidden 23 } 24 return false 25 } 26 27 func isNotFound(err error) bool { 28 if r, ok := err.(*ErrorResponse); ok { 29 return r.StatusCode == http.StatusNotFound 30 } 31 return false 32 } 33 34 type Errors []string 35 36 func (e Errors) Error() string { 37 return strings.Join(e, "; ") 38 } 39 40 type ErrorResponse struct { 41 StatusCode int 42 Errors 43 }