From 347d074dc21b76986338ba9f31c054466b38a0cf Mon Sep 17 00:00:00 2001
From: Olivier Cano <kindermoumoute@users.noreply.github.com>
Date: Mon, 30 Sep 2019 17:06:16 +0200
Subject: [PATCH] feat: add interface body getter to std err (#192)

---
 scw/errors.go | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/scw/errors.go b/scw/errors.go
index 23a4b76fe..86672113d 100644
--- a/scw/errors.go
+++ b/scw/errors.go
@@ -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)
 
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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"`
@@ -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"`
@@ -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"`
@@ -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
+}