Skip to content

Commit e5e3600

Browse files
authored
fix: handle additional non standards errors (#525)
Signed-off-by: Patrik Cyvoct <[email protected]>
1 parent ac1fb74 commit e5e3600

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

scw/errors.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ func (e *UnknownResource) ToResourceNotFoundError() SdkError {
248248
}
249249

250250
messageParts := strings.Split(e.Message, `"`)
251+
252+
// Some errors uses ' and not "
253+
if len(messageParts) == 1 {
254+
messageParts = strings.Split(e.Message, "'")
255+
}
256+
251257
switch len(messageParts) {
252258
case 2: // message like: `"111..." not found`
253259
resourceNotFound.ResourceID = messageParts[0]

scw/errors_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ func TestNonStandardError(t *testing.T) {
128128
},
129129
}))
130130

131+
t.Run("unknown_resource single qupte", run(&testCase{
132+
resStatus: "404 Not Found",
133+
resStatusCode: http.StatusNotFound,
134+
contentType: "application/json",
135+
resBody: `{"type": "unknown_resource", "message": "Volume '11111111-1111-4111-8111-111111111111' not found"}`,
136+
expectedError: &ResourceNotFoundError{
137+
ResourceID: "11111111-1111-4111-8111-111111111111",
138+
Resource: "volume",
139+
RawBody: []byte(`{"type": "unknown_resource", "message": "Volume '11111111-1111-4111-8111-111111111111' not found"}`),
140+
},
141+
}))
142+
131143
t.Run("conflict type", run(&testCase{
132144
resStatus: "409 Conflict",
133145
resStatusCode: http.StatusConflict,

0 commit comments

Comments
 (0)