Skip to content
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
}