Skip to content

Commit d1b6a3d

Browse files
committed
遇到http错误时返回body
1 parent 78f6183 commit d1b6a3d

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

cache/cache_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestCacheActive(t *testing.T) {
1010
User string
1111
Pass string
1212
}{
13-
"test@jd.com",
13+
"test@mailchina.org",
1414
"password",
1515
}
1616
c := NewCache(2)
@@ -29,7 +29,7 @@ func TestCacheInactive(t *testing.T) {
2929
User string
3030
Pass string
3131
}{
32-
"test@jd.com",
32+
"test@mailchina.org",
3333
"password",
3434
}
3535
c := NewCache(2)

config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
func TestMain(main *testing.M) {
1717
data := `
1818
[db]
19-
domain =jd.com
19+
domain =mailchina.org
2020
enable=true
2121
# test comments
2222
;port=3306

http/client/client.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ type HTTPClient struct {
2323
}
2424

2525
type StatusError struct {
26-
Code int
26+
Code int
27+
Message string
2728
}
2829

2930
func (se *StatusError) Error() string {
30-
return fmt.Sprintf("HTTP Status %v", se.Code)
31+
return fmt.Sprintf("HTTP Status %v %s", se.Code, se.Message)
3132
}
3233

3334
func (c *HTTPClient) dial(network, addr string) (net.Conn, error) {
@@ -114,7 +115,7 @@ func (c HTTPClient) do(method, url string, headers map[string]string, body []byt
114115
}
115116

116117
if resp.StatusCode != http.StatusOK {
117-
return nil, errors.Trace(&StatusError{resp.StatusCode})
118+
return nil, errors.Trace(&StatusError{Code: resp.StatusCode, Message: string(data)})
118119
}
119120

120121
return data, nil

http/server/vars_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
func TestVarsForm(t *testing.T) {
1111
url := "http://www.baidu.com/test/"
12-
body := ioutil.NopCloser(bytes.NewBufferString("email=test@jd.com&passwd=1qaz"))
12+
body := ioutil.NopCloser(bytes.NewBufferString("email=test@mailchina.org&passwd=1qaz"))
1313
req, err := http.NewRequest("POST", url, body)
1414
if err != nil {
1515
t.Fatal(err.Error())
@@ -32,7 +32,7 @@ func TestVarsHeader(t *testing.T) {
3232
if err != nil {
3333
t.Fatal(err.Error())
3434
}
35-
req.Header.Add("Email", "test@jd.com")
35+
req.Header.Add("Email", "test@mailchina.org")
3636
req.Header.Add("Passwd", "1qaz")
3737

3838
result := struct {
@@ -46,7 +46,7 @@ func TestVarsHeader(t *testing.T) {
4646
}
4747

4848
func TestVarsUrl(t *testing.T) {
49-
url := "http://www.baidu.com/test/?email=test@jd.com&passwd=1qaz"
49+
url := "http://www.baidu.com/test/?email=test@mailchina.org&passwd=1qaz"
5050
req, err := http.NewRequest("GET", url, nil)
5151
if err != nil {
5252
t.Fatal(err.Error())
@@ -64,7 +64,7 @@ func TestVarsUrl(t *testing.T) {
6464

6565
func TestVarsJSON(t *testing.T) {
6666
url := "http://www.baidu.com/test/"
67-
body := ioutil.NopCloser(bytes.NewBufferString(`{"email":"test@jd.com","passwd":"1qaz"}`))
67+
body := ioutil.NopCloser(bytes.NewBufferString(`{"email":"test@mailchina.org","passwd":"1qaz"}`))
6868
req, err := http.NewRequest("POST", url, body)
6969
if err != nil {
7070
t.Fatal(err.Error())

validation/validation_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ func TestAliase(t *testing.T) {
366366
}
367367

368368
valid := Validation{}
369-
u := user{Name: "aaaaa@jd.com", kk: "kkk", a: 1}
369+
u := user{Name: "aaaaa@mailchina.org", kk: "kkk", a: 1}
370370
_, err := valid.Valid(u)
371371
t.Logf("%+v", err)
372372
}

0 commit comments

Comments
 (0)