Skip to content
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

Merged
merged 2 commits into from
Oct 9, 2017

Conversation

michalpristas
Copy link
Contributor

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

@michalpristas michalpristas force-pushed the support-for-unwrapped-errors branch from 2cdb55b to d9ee4b3 Compare September 11, 2017 16:43
Copy link
Member

@marstr marstr left a 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.

e.ServiceError = se
} else {
e.ServiceError = &ServiceError{Code: "Unknown", Message: "Unknown service error"}
}
Copy link
Member

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",
    }
}

WithErrorUnlessStatusCode(http.StatusOK),
autorest.ByClosing())
if err == nil {
t.Fatalf("azure: returned nil error for proper error response")
Copy link
Member

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()

}

details, _ := json.Marshal(*azErr.ServiceError.Details)
if string(details) != `[{"code":"conflict1","message":"error message1"},{"code":"conflict2","message":"error message2"}]` {
Copy link
Member

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?

Copy link
Contributor Author

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 marstr self-assigned this Sep 13, 2017
@Azure Azure deleted a comment from msftclas Sep 26, 2017
@Azure Azure deleted a comment from msftclas Sep 26, 2017
@Azure Azure deleted a comment from msftclas Sep 27, 2017
@michalpristas
Copy link
Contributor Author

@marstr is something missing?

@marstr marstr changed the base branch from master to dev October 9, 2017 21:50
@marstr
Copy link
Member

marstr commented Oct 9, 2017

Sorry, to leave you hanging @michalpristas! Thanks for making the recommended changes. Merging this in now.

@marstr marstr merged commit 0c0783e into Azure:dev Oct 9, 2017
@michalpristas michalpristas deleted the support-for-unwrapped-errors branch October 10, 2017 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants