Skip to content

Commit 347d074

Browse files
feat: add interface body getter to std err (#192)
1 parent 250a123 commit 347d074

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

scw/errors.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type ResponseError struct {
3939
RawBody json.RawMessage `json:"-"`
4040
}
4141

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

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

5759
return s
5860
}
59-
60-
// IsScwSdkError implement SdkError interface
61-
func (e *ResponseError) IsScwSdkError() {}
61+
func (e *ResponseError) GetRawBody() json.RawMessage {
62+
return e.RawBody
63+
}
6264

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

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

159164
type QuotasExceededError struct {
160165
Details []struct {
@@ -176,6 +181,9 @@ func (e *QuotasExceededError) Error() string {
176181

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

180188
type PermissionsDeniedError struct {
181189
Details []struct {
@@ -196,6 +204,9 @@ func (e *PermissionsDeniedError) Error() string {
196204

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

200211
type TransientStateError struct {
201212
Resource string `json:"resource"`
@@ -210,6 +221,9 @@ func (e *TransientStateError) IsScwSdkError() {}
210221
func (e *TransientStateError) Error() string {
211222
return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is in a transient state: %s", e.Resource, e.ResourceID, e.CurrentState)
212223
}
224+
func (e *TransientStateError) GetRawBody() json.RawMessage {
225+
return e.RawBody
226+
}
213227

214228
type ResourceNotFoundError struct {
215229
Resource string `json:"resource"`
@@ -223,6 +237,9 @@ func (e *ResourceNotFoundError) IsScwSdkError() {}
223237
func (e *ResourceNotFoundError) Error() string {
224238
return fmt.Sprintf("scaleway-sdk-go: resource %s with ID %s is not found", e.Resource, e.ResourceID)
225239
}
240+
func (e *ResourceNotFoundError) GetRawBody() json.RawMessage {
241+
return e.RawBody
242+
}
226243

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

0 commit comments

Comments
 (0)