@@ -0,0 +1,44 @@
|
||||
package awsserversdk
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
StatusCode int
|
||||
Code int
|
||||
Message string
|
||||
Data json.RawMessage
|
||||
Body string
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string {
|
||||
return fmt.Sprintf("aws server API: HTTP %d code %d: %s", e.StatusCode, e.Code, e.Message)
|
||||
}
|
||||
func IsUnauthorized(err error) bool {
|
||||
value, ok := err.(*APIError)
|
||||
return ok && (value.StatusCode == http.StatusUnauthorized || value.StatusCode == http.StatusForbidden)
|
||||
}
|
||||
func IsConflict(err error) bool {
|
||||
value, ok := err.(*APIError)
|
||||
return ok && value.StatusCode == http.StatusConflict
|
||||
}
|
||||
func IsBudgetExceeded(err error) bool {
|
||||
value, ok := err.(*APIError)
|
||||
if !ok || value.StatusCode != http.StatusConflict {
|
||||
return false
|
||||
}
|
||||
var data map[string]any
|
||||
return json.Unmarshal(value.Data, &data) == nil && data["shortfall"] != nil
|
||||
}
|
||||
|
||||
type TaskError struct{ Task Task }
|
||||
|
||||
func (e *TaskError) Error() string {
|
||||
if e.Task.ErrorMessage != "" {
|
||||
return e.Task.ErrorMessage
|
||||
}
|
||||
return "operation task failed: " + e.Task.Status
|
||||
}
|
||||
Reference in New Issue
Block a user