-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add logging event EventResponseError (#22411)
* Add logging event EventResponseError This event is logged whenever an azcore.ResponseError is created. The contents are from ResponseError.Error(). Add NewResponseErrorWithErrorCode to support creating ResponseErrors when the error code is in a non-standard location. * cleanup * verify no extra logs
- Loading branch information
1 parent
0d4ed40
commit 89ee9d0
Showing
8 changed files
with
182 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package runtime | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/internal/exported" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNewResponseError(t *testing.T) { | ||
fakeURL, err := url.Parse("https://contoso.com") | ||
require.NoError(t, err) | ||
err = NewResponseError(&http.Response{ | ||
Status: "the system is down", | ||
StatusCode: http.StatusInternalServerError, | ||
Body: io.NopCloser(strings.NewReader(`{ "code": "ErrorItsBroken", "message": "it's not working" }`)), | ||
Request: &http.Request{ | ||
Method: http.MethodGet, | ||
URL: fakeURL, | ||
}, | ||
}) | ||
var respErr *exported.ResponseError | ||
require.ErrorAs(t, err, &respErr) | ||
require.EqualValues(t, http.StatusInternalServerError, respErr.StatusCode) | ||
require.EqualValues(t, "ErrorItsBroken", respErr.ErrorCode) | ||
require.NotNil(t, respErr.RawResponse) | ||
} | ||
|
||
func TestNewResponseErrorWithErrorCode(t *testing.T) { | ||
fakeURL, err := url.Parse("https://contoso.com") | ||
require.NoError(t, err) | ||
err = NewResponseErrorWithErrorCode(&http.Response{ | ||
Status: "the system is down", | ||
StatusCode: http.StatusInternalServerError, | ||
Request: &http.Request{ | ||
Method: http.MethodGet, | ||
URL: fakeURL, | ||
}, | ||
}, "ErrorItsBroken") | ||
var respErr *exported.ResponseError | ||
require.ErrorAs(t, err, &respErr) | ||
require.EqualValues(t, http.StatusInternalServerError, respErr.StatusCode) | ||
require.EqualValues(t, "ErrorItsBroken", respErr.ErrorCode) | ||
require.NotNil(t, respErr.RawResponse) | ||
} |