opentofu/builtin/providers/packet/errors.go
Andrew Hodges a1935a135d Handle external state changes for Packet resources gracefully.
When a Packet provision exceeds our time limit, we move the device to an
internal project for Packet staff to investigate. When this happens, the
original user no longer has access to the device, and they get a 403.

These changes make that and other external state changes more pleasant for
users of Terraform.
2016-01-14 10:50:15 -05:00

44 lines
711 B
Go

package packet
import (
"net/http"
"strings"
"github.com/packethost/packngo"
)
func friendlyError(err error) error {
if e, ok := err.(*packngo.ErrorResponse); ok {
return &ErrorResponse{
StatusCode: e.Response.StatusCode,
Errors: Errors(e.Errors),
}
}
return err
}
func isForbidden(err error) bool {
if r, ok := err.(*ErrorResponse); ok {
return r.StatusCode == http.StatusForbidden
}
return false
}
func isNotFound(err error) bool {
if r, ok := err.(*ErrorResponse); ok {
return r.StatusCode == http.StatusNotFound
}
return false
}
type Errors []string
func (e Errors) Error() string {
return strings.Join(e, "; ")
}
type ErrorResponse struct {
StatusCode int
Errors
}