File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
sdk/azcore/internal/shared Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ func extractErrorCodeJSON(body []byte) string {
59
59
return ""
60
60
}
61
61
rawObj = unwrapped
62
+ } else if wrapped , ok := rawObj ["odata.error" ]; ok {
63
+ // check if this a wrapped odata error, i.e. { "odata.error": { ... } }
64
+ unwrapped , ok := wrapped .(map [string ]any )
65
+ if ! ok {
66
+ return ""
67
+ }
68
+ rawObj = unwrapped
62
69
}
63
70
64
71
// now check for the error code
Original file line number Diff line number Diff line change @@ -420,3 +420,31 @@ ERROR CODE UNAVAILABLE
420
420
t .Fatalf ("\n got:\n %s\n want:\n %s\n " , got , want )
421
421
}
422
422
}
423
+
424
+ func TestExtractErrorCodeFromJSON (t * testing.T ) {
425
+ errorBody := []byte (`{"odata.error": {
426
+ "code": "ResourceNotFound",
427
+ "message": {
428
+ "lang": "en-us",
429
+ "value": "The specified resource does not exist.\nRequestID:b2437f3b-ca2d-47a1-95a7-92f73a768a1c\n"
430
+ }
431
+ }
432
+ }` )
433
+ code := extractErrorCodeJSON (errorBody )
434
+ if code != "ResourceNotFound" {
435
+ t .Fatalf ("expected %s got %s" , "ResourceNotFound" , code )
436
+ }
437
+
438
+ errorBody = []byte (`{"error": {
439
+ "code": "ResourceNotFound",
440
+ "message": {
441
+ "lang": "en-us",
442
+ "value": "The specified resource does not exist.\nRequestID:b2437f3b-ca2d-47a1-95a7-92f73a768a1c\n"
443
+ }
444
+ }
445
+ }` )
446
+ code = extractErrorCodeJSON (errorBody )
447
+ if code != "ResourceNotFound" {
448
+ t .Fatalf ("expected %s got %s" , "ResourceNotFound" , code )
449
+ }
450
+ }
You can’t perform that action at this time.
0 commit comments