diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bbc74b..0a0d7f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,12 @@ # Change Log +## v2.7.1 + +- `[FIX]` [#232](https://github.com/huandu/facebook/issues/232) Fix incorrect error wrapping. Thanks, [@AnatolyRugalev](https://github.com/AnatolyRugalev). + ## v2.7.0 -- `[NEW]` [#211](https://github.com/huandu/facebook/pull/211) Make session on app configurable. Thank [Spazzy757](https://github.com/Spazzy757) for your PR. +- `[NEW]` [#211](https://github.com/huandu/facebook/pull/211) Make session on app configurable. Thank [@Spazzy757](https://github.com/Spazzy757) for your PR. ## v2.6.0 diff --git a/app.go b/app.go index df42eed..d6fd13d 100644 --- a/app.go +++ b/app.go @@ -67,21 +67,21 @@ func (app *App) ParseSignedRequest(signedRequest string) (res Result, err error) sig, e1 := base64.RawURLEncoding.DecodeString(strs[0]) if e1 != nil { - err = fmt.Errorf("facebook: fail to decode signed request sig with error %v", e1) + err = fmt.Errorf("facebook: fail to decode signed request sig with error %w", e1) return } payload, e2 := base64.RawURLEncoding.DecodeString(strs[1]) if e2 != nil { - err = fmt.Errorf("facebook: fail to decode signed request payload with error is %v", e2) + err = fmt.Errorf("facebook: fail to decode signed request payload with error is %w", e2) return } err = json.Unmarshal(payload, &res) if err != nil { - err = fmt.Errorf("facebook: signed request payload is not a valid json string with error %v", err) + err = fmt.Errorf("facebook: signed request payload is not a valid json string with error %w", err) return } @@ -142,7 +142,7 @@ func (app *App) ParseCodeInfo(code, machineID string) (token string, expires int }) if err != nil { - err = fmt.Errorf("facebook: fail to parse facebook response with error %v", err) + err = fmt.Errorf("facebook: fail to parse facebook response with error %w", err) return } @@ -190,7 +190,7 @@ func (app *App) ExchangeToken(accessToken string) (token string, expires int, er }) if err != nil { - err = fmt.Errorf("fail to parse facebook response with error %v", err) + err = fmt.Errorf("fail to parse facebook response with error %w", err) return } @@ -230,7 +230,7 @@ func (app *App) GetCode(accessToken string) (code string, err error) { }) if err != nil { - err = fmt.Errorf("facebook: fail to get code from facebook with error %v", err) + err = fmt.Errorf("facebook: fail to get code from facebook with error %w", err) return } diff --git a/result.go b/result.go index 50deba2..e545adb 100644 --- a/result.go +++ b/result.go @@ -328,19 +328,19 @@ func getValueField(value reflect.Value, fields []string) reflect.Value { // // Examples: // -// type Foo struct { -// // "id" must exist in response. note the leading comma. -// Id string `facebook:",required"` +// type Foo struct { +// // "id" must exist in response. note the leading comma. +// Id string `facebook:",required"` // -// // use "name" as field name in response. -// TheName string `facebook:"name"` +// // use "name" as field name in response. +// TheName string `facebook:"name"` // -// // the "json" key also works as expected. -// Key string `json:"my_key"` +// // the "json" key also works as expected. +// Key string `json:"my_key"` // -// // if both "facebook" and "json" key are set, the "facebook" key is used. -// Value string `facebook:"value" json:"shadowed"` -// } +// // if both "facebook" and "json" key are set, the "facebook" key is used. +// Value string `facebook:"value" json:"shadowed"` +// } // // To change default behavior, set a struct tag `facebook:",required"` to fields // should not be missing. @@ -388,12 +388,13 @@ func (res Result) DecodeField(field string, v interface{}) error { // Err returns an error if Result is a Graph API error. // // The returned error can be converted to Error by type assertion. -// err := res.Err() -// if err != nil { -// if e, ok := err.(*Error); ok { -// // read more details in e.Message, e.Code and e.Type -// } -// } +// +// err := res.Err() +// if err != nil { +// if e, ok := err.(*Error); ok { +// // read more details in e.Message, e.Code and e.Type +// } +// } // // For more information about Graph API Errors, see // https://developers.facebook.com/docs/reference/api/errors/ @@ -420,13 +421,14 @@ func (res Result) Err() error { // // Facebook uses following JSON structure to response paging information. // If "data" doesn't present in Result, Paging will return error. -// { -// "data": [...], -// "paging": { -// "previous": "https://graph.facebook.com/...", -// "next": "https://graph.facebook.com/..." -// } -// } +// +// { +// "data": [...], +// "paging": { +// "previous": "https://graph.facebook.com/...", +// "next": "https://graph.facebook.com/..." +// } +// } func (res Result) Paging(session *Session) (*PagingResult, error) { return newPagingResult(session, res) } @@ -614,7 +616,7 @@ func decodeField(val reflect.Value, field reflect.Value, fullName string) error data, err := json.Marshal(val.Interface()) if err != nil { - return fmt.Errorf("facebook: fail to marshal value for field '%v' with error %v", fullName, err) + return fmt.Errorf("facebook: fail to marshal value for field '%v' with error %w", fullName, err) } return unmarshaler.UnmarshalJSON(data) diff --git a/session.go b/session.go index 79d9dd2..6173313 100644 --- a/session.go +++ b/session.go @@ -476,7 +476,7 @@ func (session *Session) sendPostRequest(uri string, params Params, res interface mime, err := params.Encode(buf) if err != nil { - return nil, fmt.Errorf("facebook: cannot encode POST params; %v", err) + return nil, fmt.Errorf("facebook: cannot encode POST params; %w", err) } request, err := http.NewRequest("POST", uri, buf) @@ -502,7 +502,7 @@ func (session *Session) sendOauthRequest(uri string, params Params) (Result, err mime, err := params.Encode(buf) if err != nil { - return nil, fmt.Errorf("facebook: cannot encode POST params; %v", err) + return nil, fmt.Errorf("facebook: cannot encode POST params; %w", err) } request, err := http.NewRequest("POST", urlStr, buf) @@ -562,7 +562,7 @@ func (session *Session) sendRequest(request *http.Request) (response *http.Respo } if err != nil { - err = fmt.Errorf("facebook: cannot reach facebook server; %v", err) + err = fmt.Errorf("facebook: cannot reach facebook server; %w", err) return } @@ -571,7 +571,7 @@ func (session *Session) sendRequest(request *http.Request) (response *http.Respo response.Body.Close() if err != nil { - err = fmt.Errorf("facebook: cannot read facebook response; %v", err) + err = fmt.Errorf("facebook: cannot read facebook response; %w", err) } data = buf.Bytes()