@@ -16,6 +16,7 @@ import (
1616 "net/http/cookiejar"
1717 urlpkg "net/url"
1818 "os"
19+ "reflect"
1920 "strings"
2021 "time"
2122)
@@ -36,23 +37,23 @@ var defaultClient *Client = C()
3637
3738// Client is the req's http client.
3839type Client struct {
39- BaseURL string
40- PathParams map [string ]string
41- QueryParams urlpkg.Values
42- Headers http.Header
43- Cookies []* http.Cookie
44- FormData urlpkg.Values
45- DebugLog bool
46- AllowGetMethodPayload bool
47-
40+ BaseURL string
41+ PathParams map [string ]string
42+ QueryParams urlpkg.Values
43+ Headers http.Header
44+ Cookies []* http.Cookie
45+ FormData urlpkg.Values
46+ DebugLog bool
47+ AllowGetMethodPayload bool
48+ trace bool
49+ disableAutoReadResponse bool
50+ commonErrorType reflect.Type
4851 retryOption * retryOption
4952 jsonMarshal func (v interface {}) ([]byte , error )
5053 jsonUnmarshal func (data []byte , v interface {}) error
5154 xmlMarshal func (v interface {}) ([]byte , error )
5255 xmlUnmarshal func (data []byte , v interface {}) error
53- trace bool
5456 outputDirectory string
55- disableAutoReadResponse bool
5657 scheme string
5758 log Logger
5859 t * Transport
@@ -72,6 +73,15 @@ func (c *Client) R() *Request {
7273 }
7374}
7475
76+ // SetCommonError set the common result that response body will be unmarshalled to
77+ // if it is an error response ( status `code >= 400`).
78+ func (c * Client ) SetCommonError (err interface {}) * Client {
79+ if err != nil {
80+ c .commonErrorType = util .GetType (err )
81+ }
82+ return c
83+ }
84+
7585// SetCommonFormDataFromValues set the form data from url.Values for all requests
7686// which request method allows payload.
7787func (c * Client ) SetCommonFormDataFromValues (data urlpkg.Values ) * Client {
0 commit comments