-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4676 from betawaffle/packet-failure-handling
Handle external state changes for Packet resources gracefully.
- Loading branch information
Showing
8 changed files
with
119 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.