-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
392 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package azure | ||
|
||
import ( | ||
"net/http" | ||
"reflect" | ||
) | ||
|
||
// ResponseError is a wrapper around an error response from the Azure Key Vault service. | ||
type ResponseError struct { | ||
// ErrorCode is the error code returned by the resource provider if available. | ||
ErrorCode string | ||
|
||
// StatusCode is the HTTP status code as defined in https://pkg.go.dev/net/http#pkg-constants. | ||
StatusCode int | ||
|
||
// RawResponse is the underlying HTTP response. | ||
RawResponse *http.Response | ||
|
||
errorResponse errorResponse | ||
} | ||
|
||
// TransportErrToResponseError converts a transport error to a ResponseError. | ||
func TransportErrToResponseError(terr error) (*ResponseError, bool) { | ||
if reflect.TypeOf(terr).String() == "*exported.ResponseError" { | ||
tv := reflect.ValueOf(terr).Elem() | ||
ErrorCode := tv.FieldByName("ErrorCode").String() | ||
StatusCode := int(tv.FieldByName("StatusCode").Int()) | ||
RawResponse, ok := tv.FieldByName("RawResponse").Interface().(*http.Response) | ||
var errorResponse errorResponse | ||
if ok { | ||
errorResponse, _ = parseErrorResponse(RawResponse) | ||
} | ||
return &ResponseError{ | ||
ErrorCode: ErrorCode, | ||
StatusCode: StatusCode, | ||
RawResponse: RawResponse, | ||
errorResponse: errorResponse, | ||
}, true | ||
} | ||
return nil, false | ||
} |
Oops, something went wrong.