Skip to content

Commit 9f66af5

Browse files
committed
Changes after review
1 parent 9c857d6 commit 9f66af5

File tree

10 files changed

+21
-79
lines changed

10 files changed

+21
-79
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +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-
// messagebird.ErrResponse means custom JSON errors.
42-
if err == messagebird.ErrResponse {
43-
for _, mbError := range balance.Errors {
44-
fmt.Printf("Error: %#v\n", mbError)
45-
}
46-
}
47-
48-
return
41+
switch errResp := err.(type) {
42+
case messagebird.ErrorResponse:
43+
for _, mbError := range errResp.Errors {
44+
fmt.Printf("Error: %#v\n", mbError)
45+
}
46+
}
47+
48+
return
4949
}
5050

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

balance.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,4 @@ type Balance struct {
55
Payment string
66
Type string
77
Amount float32
8-
Errors []Error // Deprecated: errors now returned at ErrorResponse instance as error.
98
}

client.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,6 @@ func New(accessKey string) *Client {
7272
}
7373
}
7474

75-
// NewV2 creates a new MessageBird client object.
76-
// Deprecated: use New factory instead.
77-
func NewV2(accessKey string) *Client {
78-
return New(accessKey)
79-
}
80-
8175
// Request is for internal use only and unstable.
8276
func (c *Client) Request(v interface{}, method, path string, data interface{}) error {
8377
if !strings.HasPrefix(path, "https://") && !strings.HasPrefix(path, "http://") {

error.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package messagebird
22

3-
import "fmt"
3+
const (
4+
apiErrMessage = "The MessageBird API returned an error"
5+
)
46

57
// Error holds details including error code, human readable description and optional parameter that is related to the error.
68
type Error struct {
@@ -9,20 +11,17 @@ type Error struct {
911
Parameter string
1012
}
1113

14+
// Error implements error interface.
15+
func (e Error) Error() string {
16+
return e.Description
17+
}
18+
1219
// ErrorResponse represents errored API response.
1320
type ErrorResponse struct {
1421
Errors []Error `json:"errors"`
1522
}
1623

1724
// Error implements error interface.
1825
func (r ErrorResponse) Error() string {
19-
eString := "API returned an error: "
20-
for i, e := range r.Errors {
21-
eString = eString + fmt.Sprintf("code: %d, description: %s, parameter: %s", e.Code, e.Description, e.Parameter)
22-
if i < len(r.Errors)-1 {
23-
eString = eString + ", "
24-
}
25-
}
26-
27-
return eString
26+
return apiErrMessage
2827
}

error_test.go

Lines changed: 0 additions & 48 deletions
This file was deleted.

hlr.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ type HLR struct {
1717
Details map[string]interface{}
1818
CreatedDatetime *time.Time
1919
StatusDatetime *time.Time
20-
Errors []Error // Deprecated: errors now returned at ErrorResponse instance as error.
2120
}
2221

2322
// HLRList represents a list of HLR requests.

message.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ type Message struct {
2929
ScheduledDatetime *time.Time
3030
CreatedDatetime *time.Time
3131
Recipients Recipients
32-
Errors []Error // Deprecated: errors now returned at ErrorResponse instance as error.
3332
}
3433

3534
// MessageList represents a list of Messages.

mms_message.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ type MMSMessage struct {
2020
ScheduledDatetime *time.Time
2121
CreatedDatetime *time.Time
2222
Recipients Recipients
23-
Errors []Error // Deprecated: errors now returned at ErrorResponse instance as error
2423
}
2524

2625
// MMSMessageParams represents the parameters that can be supplied when creating

mms_message_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ func TestNewMMSMessage(t *testing.T) {
9494
if mmsMessage.Recipients.Items[0].StatusDatetime == nil || mmsMessage.Recipients.Items[0].StatusDatetime.Format(time.RFC3339) != "2017-10-20T12:50:28Z" {
9595
t.Errorf("Unexpected datetime status for mmsMessage recipient: %s", mmsMessage.Recipients.Items[0].StatusDatetime.Format(time.RFC3339))
9696
}
97-
if len(mmsMessage.Errors) != 0 {
98-
t.Errorf("Unexpected number of errors in mmsMessage: %d", len(mmsMessage.Errors))
97+
98+
errorResponse, ok := err.(ErrorResponse)
99+
if ok {
100+
t.Errorf("Unexpected error returned with mmsMessage %#v", errorResponse)
99101
}
100102
}
101103

verify.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type Verify struct {
1515
CreatedDatetime *time.Time
1616
ValidUntilDatetime *time.Time
1717
Recipient int
18-
Errors []Error // Deprecated: errors now returned at ErrorResponse instance as error.
1918
}
2019

2120
// VerifyParams handles optional verification parameters.

0 commit comments

Comments
 (0)