Skip to content

Commit

Permalink
feat: add interface body getter to std err
Browse files Browse the repository at this point in the history
  • Loading branch information
kindermoumoute committed Sep 25, 2019
1 parent 5cf7cef commit 31d82a0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions scw/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type ResponseError struct {
RawBody json.RawMessage `json:"-"`
}

// IsScwSdkError implement SdkError interface
func (e *ResponseError) IsScwSdkError() {}
func (e *ResponseError) Error() string {
s := fmt.Sprintf("scaleway-sdk-go: http error %s", e.Status)

Expand All @@ -56,9 +58,9 @@ func (e *ResponseError) Error() string {

return s
}

// IsScwSdkError implement SdkError interface
func (e *ResponseError) IsScwSdkError() {}
func (e *ResponseError) GetRawBody() json.RawMessage {
return e.RawBody
}

// hasResponseError throws an error when the HTTP status is not OK
func hasResponseError(res *http.Response) SdkError {
Expand Down Expand Up @@ -153,6 +155,9 @@ func (e *InvalidArgumentsError) Error() string {

return "scaleway-sdk-go: invalid argument(s): " + strings.Join(invalidArgs, "; ")
}
func (e *InvalidArgumentsError) GetRawBody() json.RawMessage {
return e.RawBody
}

type QuotasExceededError struct {
Details []struct {
Expand All @@ -174,6 +179,9 @@ func (e *QuotasExceededError) Error() string {

return "scaleway-sdk-go: quota exceeded(s): " + strings.Join(invalidArgs, "; ")
}
func (e *QuotasExceededError) GetRawBody() json.RawMessage {
return e.RawBody
}

type PermissionsDeniedError struct {
Details []struct {
Expand All @@ -194,6 +202,9 @@ func (e *PermissionsDeniedError) Error() string {

return "scaleway-sdk-go: insufficient permissions: " + strings.Join(invalidArgs, "; ")
}
func (e *PermissionsDeniedError) GetRawBody() json.RawMessage {
return e.RawBody
}

type TransientStateError struct {
Resource string `json:"resource"`
Expand All @@ -208,6 +219,9 @@ func (e *TransientStateError) IsScwSdkError() {}
func (e *TransientStateError) Error() string {
return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is in a transient state: %s", e.Resource, e.ResourceID, e.CurrentState)
}
func (e *TransientStateError) GetRawBody() json.RawMessage {
return e.RawBody
}

type ResourceNotFound struct {
Resource string `json:"resource"`
Expand All @@ -221,3 +235,6 @@ func (e *ResourceNotFound) IsScwSdkError() {}
func (e *ResourceNotFound) Error() string {
return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is not found", e.Resource, e.ResourceID)
}
func (e *ResourceNotFound) GetRawBody() json.RawMessage {
return e.RawBody
}

0 comments on commit 31d82a0

Please sign in to comment.