mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-09 07:33:58 -06:00
a1935a135d
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.
44 lines
711 B
Go
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
|
|
}
|