@@ -348,6 +348,43 @@ ERROR CODE: ContainerAlreadyExists
348
348
}
349
349
}
350
350
351
+ func TestNewResponseErrorErrorCodeHeaderXMLWithNamespace (t * testing.T ) {
352
+ fakeURL , err := url .Parse ("https://fakeurl.com/the/path?qp=removed" )
353
+ if err != nil {
354
+ t .Fatal (err )
355
+ }
356
+ respHeader := http.Header {}
357
+ respHeader .Set ("x-ms-error-code" , "ContainerAlreadyExists" )
358
+ err = NewResponseError (& http.Response {
359
+ Status : "the system is down" ,
360
+ StatusCode : http .StatusInternalServerError ,
361
+ Header : respHeader ,
362
+ Body : io .NopCloser (strings .NewReader (`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><m:Error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:Code>ContainerAlreadyExists</m:Code><m:Message>The specified container already exists.\nRequestId:73b2473b-c1c8-4162-97bb-dc171bff61c9\nTime:2021-12-13T19:45:40.679Z</m:Message></m:Error>` )),
363
+ Request : & http.Request {
364
+ Method : http .MethodGet ,
365
+ URL : fakeURL ,
366
+ },
367
+ })
368
+ re , ok := err .(* ResponseError )
369
+ if ! ok {
370
+ t .Fatalf ("unexpected error type %T" , err )
371
+ }
372
+ if c := re .StatusCode ; c != http .StatusInternalServerError {
373
+ t .Fatalf ("unexpected status code %d" , c )
374
+ }
375
+ const want = `GET https://fakeurl.com/the/path
376
+ --------------------------------------------------------------------------------
377
+ RESPONSE 500: the system is down
378
+ ERROR CODE: ContainerAlreadyExists
379
+ --------------------------------------------------------------------------------
380
+ <?xml version="1.0" encoding="UTF-8" standalone="yes"?><m:Error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:Code>ContainerAlreadyExists</m:Code><m:Message>The specified container already exists.\nRequestId:73b2473b-c1c8-4162-97bb-dc171bff61c9\nTime:2021-12-13T19:45:40.679Z</m:Message></m:Error>
381
+ --------------------------------------------------------------------------------
382
+ `
383
+ if got := re .Error (); got != want {
384
+ t .Fatalf ("\n got:\n %s\n want:\n %s\n " , got , want )
385
+ }
386
+ }
387
+
351
388
func TestNewResponseErrorAllMissingXML (t * testing.T ) {
352
389
fakeURL , err := url .Parse ("https://fakeurl.com/the/path?qp=removed" )
353
390
if err != nil {
0 commit comments