Merge lp:~jtv/gwacl/http-error into lp:gwacl
Status: | Merged |
---|---|
Approved by: | Jeroen T. Vermeulen |
Approved revision: | 69 |
Merged at revision: | 68 |
Proposed branch: | lp:~jtv/gwacl/http-error |
Merge into: | lp:gwacl |
Diff against target: |
485 lines (+192/-90) 9 files modified
example/live_example_managementapi.go (+2/-1) httperror.go (+77/-0) httperror_test.go (+68/-0) storage.go (+14/-25) storage_test.go (+19/-5) x509session.go (+6/-18) x509session_test.go (+6/-6) xmlobjects.go (+0/-17) xmlobjects_test.go (+0/-18) |
To merge this branch: | bzr merge lp:~jtv/gwacl/http-error |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Raphaël Badin (community) | Approve | ||
Review via email: mp+155679@code.launchpad.net |
Commit message
Harmonize "error based on http response" types.
Description of the change
This code replaces our existing Error and ServerError structs with one interface: HTTPError. It's an "error" but with an added Status() for the HTTP status code.
Underneath, there are two implementations: ServerError represents any HTTP error response. AzureError is an error message from Azure itself, with more details embedded as XML. For now we don't have any need to distinguish between them, so Error() and Status() are the only methods we need. A single factory selects and produces the right implementation, so all kinds of HTTP errors are automatically handled wherever we use the new types. We get better Azure errors in the management API as a free part of the bargain.
You may wonder how HTTPStatus works. It's a type based on int, but it adds a Status() method. And so both ServerError and AzureError implement their Status() methods simply by embedding an HTTPStatus. Effectively it's a member whose name matches its type and whose methods get added to those of the surrounding struct.
There are a few more places I can clean up now, because send() now returns an "error" instead of a "*Error" — so there's no more risk of accidentally converting a nil "*Error" to a non-nil "error." But this branch touches a lot of code (mostly unavoidable changes that just came along) so let's stop it from growing even further!
Jeroen
Looks good, a very nice improvement!
[0]
28 +// HTTPError is an extended version of the standard "error" interface. It
29 +// adds an HTTP status code.
30 +type HTTPError interface {
31 + error
32 + Status() int
33 +}
For clarity, I'd be in favor of renaming Status() into StatusCode().
[1]
253 + c.Check(err, ErrorMatches, ".*102.*")
254 + c.Check(err, ErrorMatches, ".*Frotzed.*")
and
265 + c.Check(err, ErrorMatches, ".*102.*")
266 + c.Check(err, ErrorMatches, ".*Frotzed.*")
and
277 + c.Check(err, ErrorMatches, ".*102.*")
278 + c.Check(err, ErrorMatches, ".*Frotzed.*")
and
289 + c.Check(err, ErrorMatches, ".*146.*")
290 + c.Check(err, ErrorMatches, ".*Frotzed.*")
and
300 + c.Check(err, ErrorMatches, ".*246.*")
301 + c.Check(err, ErrorMatches, ".*Frotzed.*")
I think you should fold these into on statement like this:
c.Check(err, ErrorMatches, ".*102 Frotzed.*")
because the status of the response is "102 Frotzed":
response := &http.Response{ NopCloser( strings. NewReader( "<Error> <Code>Frotzed< /Code>< Message> failed to put blob</Message> </Error> ")),
Status: "102 Frotzed",
StatusCode: 102,
Body: ioutil.
}