Merge lp:~allenap/gwacl/extend-azure-error into lp:gwacl

Proposed by Gavin Panella on 2013-07-11
Status: Merged
Approved by: Gavin Panella on 2013-07-11
Approved revision: 177
Merged at revision: 177
Proposed branch: lp:~allenap/gwacl/extend-azure-error
Merge into: lp:gwacl
Diff against target: 65 lines (+29/-14)
2 files modified
httperror.go (+7/-3)
httperror_test.go (+22/-11)
To merge this branch: bzr merge lp:~allenap/gwacl/extend-azure-error
Reviewer Review Type Date Requested Status
Raphaël Badin (community) 2013-07-11 Approve on 2013-07-11
Review via email: mp+174165@code.launchpad.net

Commit message

Ensure that extendError() treats AzureError specially too.

To post a comment you must log in.
Raphaël Badin (rvb) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'httperror.go'
2--- httperror.go 2013-07-09 20:01:18 +0000
3+++ httperror.go 2013-07-11 10:55:34 +0000
4@@ -103,9 +103,13 @@
5 func extendError(err error, message string) error {
6 switch err := err.(type) {
7 case *ServerError:
8- returnedErr := *err
9- returnedErr.error = fmt.Errorf(message+"%v", err.error)
10- return &returnedErr
11+ extendedError := *err
12+ extendedError.error = fmt.Errorf(message+"%v", err.error)
13+ return &extendedError
14+ case *AzureError:
15+ extendedError := *err
16+ extendedError.error = fmt.Errorf(message+"%v", err.error)
17+ return &extendedError
18 default:
19 return fmt.Errorf(message+"%v", err)
20 }
21
22=== modified file 'httperror_test.go'
23--- httperror_test.go 2013-07-09 20:01:18 +0000
24+++ httperror_test.go 2013-07-11 10:55:34 +0000
25@@ -104,18 +104,29 @@
26 }
27
28 func (suite *httpErrorSuite) TestExtendErrorExtendsServerError(c *C) {
29- description := "could not talk to server"
30- status := http.StatusGatewayTimeout
31- httpErr := newHTTPError(status, []byte{}, description)
32+ err := &ServerError{
33+ error: errors.New("could not talk to server"),
34+ HTTPStatus: HTTPStatus(http.StatusGatewayTimeout),
35+ }
36+ additionalErrorMsg := "additional message: "
37+ newError := extendError(err, additionalErrorMsg)
38+ newServerError, ok := newError.(*ServerError)
39+ c.Assert(ok, Equals, true)
40+ c.Check(newError.Error(), Equals, additionalErrorMsg+err.Error())
41+ c.Check(newServerError.HTTPStatus, Equals, err.HTTPStatus)
42+}
43
44- httpServerErr, ok := httpErr.(*ServerError)
45- c.Assert(ok, Equals, true)
46- additionalErrorMsg := "additional message"
47- newError := extendError(httpErr, additionalErrorMsg)
48- newServerError, ok := httpErr.(*ServerError)
49- c.Assert(ok, Equals, true)
50- c.Check(newError.Error(), Equals, fmt.Sprintf("%s%s", additionalErrorMsg, httpErr.Error()))
51- c.Check(httpServerErr.HTTPStatus, Equals, newServerError.HTTPStatus)
52+func (suite *httpErrorSuite) TestExtendErrorExtendsAzureError(c *C) {
53+ err := &AzureError{
54+ error: errors.New("could not talk to server"),
55+ HTTPStatus: HTTPStatus(http.StatusGatewayTimeout),
56+ }
57+ additionalErrorMsg := "additional message: "
58+ newError := extendError(err, additionalErrorMsg)
59+ newAzureError, ok := newError.(*AzureError)
60+ c.Assert(ok, Equals, true)
61+ c.Check(newError.Error(), Equals, additionalErrorMsg+err.Error())
62+ c.Check(newAzureError.HTTPStatus, Equals, err.HTTPStatus)
63 }
64
65 func (suite *httpErrorSuite) TestIsNotFound(c *C) {

Subscribers

People subscribed via source and target branches

to all changes: