-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/improve error and requester (#44)
* Remove pointer from responses * Update unit tests * Update integration tests * Update examples * Update customer struct * Order struct fields * Change int64 to int * Switch params order * Externalize Requester interface * Improve internal tests * Externalize response error
- Loading branch information
1 parent
4e788fd
commit ca46968
Showing
10 changed files
with
81 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,4 @@ threshold: | |
|
||
exclude: | ||
paths: | ||
- ^pkg/internal | ||
- ^pkg/config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/mercadopago/sdk-go/pkg/config" | ||
"github.com/mercadopago/sdk-go/pkg/mperror" | ||
"github.com/mercadopago/sdk-go/pkg/payment" | ||
) | ||
|
||
func main() { | ||
accessToken := "{{ACCESS_TOKEN}}" | ||
|
||
cfg, err := config.New(accessToken) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
invalidRequest := payment.Request{} | ||
|
||
client := payment.NewClient(cfg) | ||
payment, err := client.Create(context.Background(), invalidRequest) | ||
if err != nil { | ||
var mpErr *mperror.ResponseError | ||
if errors.As(err, &mpErr) { | ||
fmt.Printf("\nheaders: %s\nmessage: %s\nstatus code: %d", mpErr.Headers, mpErr.Message, mpErr.StatusCode) | ||
return | ||
} | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
fmt.Println(payment) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package httpclient | ||
package mperror | ||
|
||
import "net/http" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package requester | ||
|
||
import "net/http" | ||
|
||
// Requester has the minimum required method to send http requests. | ||
type Requester interface { | ||
Do(req *http.Request) (*http.Response, error) | ||
} |