Skip to content

Commit 0ab1da8

Browse files
committed
Update the README to reflect the new wat to detect JSON errors
1 parent 3dd0b3c commit 0ab1da8

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

README.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ Now you can query the API for information or send data. For example, if we want
3838
// Request the balance information, returned as a Balance object.
3939
balance, err := client.Balance()
4040
if err != nil {
41-
fmt.Println(err)
42-
os.Exit(1)
43-
}
44-
45-
// Check for errors returned as JSON.
46-
if len(balance.Errors) != 0 {
47-
for _, error := range balance.Errors {
48-
fmt.Println(" code :", error.Code)
49-
fmt.Println(" description :", error.Description)
50-
fmt.Println(" parameter :", error.Parameter)
51-
}
52-
os.Exit(1)
41+
// messagebird.ErrResponse means custom JSON errors.
42+
if err == messagebird.ErrResponse {
43+
for _, mbError := range object.Errors {
44+
fmt.Printf("Error: %#v\n", mbError)
45+
}
46+
}
47+
48+
return
5349
}
5450

5551
fmt.Println(" payment :", balance.Payment)

0 commit comments

Comments
 (0)