-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added support for unwrapped Azure API error responses #170
Conversation
2cdb55b
to
d9ee4b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for getting to this! I know this is something everybody will appreciate, but has been in backlog purgatory.
I have a few minor requests to fix up before this is accepted, however.
autorest/azure/azure.go
Outdated
e.ServiceError = se | ||
} else { | ||
e.ServiceError = &ServiceError{Code: "Unknown", Message: "Unknown service error"} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should be updated to:
var se ServiceError
if err := json.Unmarshal(b.Bytes(), &se); err == nil && se.Message != "" {
e.ServiceError = &se
} else {
e.ServiceError = &ServiceError{
Code: "Unknown",
Message: "Unknown service error",
}
}
autorest/azure/azure_test.go
Outdated
WithErrorUnlessStatusCode(http.StatusOK), | ||
autorest.ByClosing()) | ||
if err == nil { | ||
t.Fatalf("azure: returned nil error for proper error response") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using t.Fatalf
ends all test execution. Please update these calls to be of the pattern:
t.Logf("[your stuff]", [any args you need])
t.Fail()
autorest/azure/azure_test.go
Outdated
} | ||
|
||
details, _ := json.Marshal(*azErr.ServiceError.Details) | ||
if string(details) != `[{"code":"conflict1","message":"error message1"},{"code":"conflict2","message":"error message2"}]` { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A Go idiom is to print out "got" and "want" in this case, one would expect the Unit Test Log to read the following on failure:
got: "{contents of details}"
want: "[{"code":"conflict1","message":"error message1"},{"code":"conflict2","message":"error message2"}]"
Mind refactoring this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will prepare fix today
@marstr is something missing? |
Sorry, to leave you hanging @michalpristas! Thanks for making the recommended changes. Merging this in now. |
Should solve problem described here: Azure/azure-sdk-for-go#748
The problem is that result of API call is ServiceError itself, not ServiceError wrapped in error object. Which causes autorest to return 'Unknown' error instead.
Fixes: 748