Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add interface body getter to std err #192

Merged
merged 1 commit into from
Sep 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 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 @@ -155,6 +157,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 @@ -176,6 +181,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 @@ -196,6 +204,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 @@ -210,6 +221,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 ResourceNotFoundError struct {
Resource string `json:"resource"`
Expand All @@ -223,6 +237,9 @@ func (e *ResourceNotFoundError) IsScwSdkError() {}
func (e *ResourceNotFoundError) Error() string {
return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is not found", e.Resource, e.ResourceID)
}
func (e *ResourceNotFoundError) GetRawBody() json.RawMessage {
return e.RawBody
}

type OutOfStockError struct {
Resource string `json:"resource"`
Expand All @@ -235,3 +252,6 @@ func (e *OutOfStockError) IsScwSdkError() {}
func (e *OutOfStockError) Error() string {
return fmt.Sprintf("scaleway-sdk-go: resource %s is out of stock", e.Resource)
}
func (e *OutOfStockError) GetRawBody() json.RawMessage {
return e.RawBody
}