Skip to content

Commit 1f52e20

Browse files
committed
Improve error decoding/output
1 parent 3e73dde commit 1f52e20

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

error.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
"strings"
78
)
89

910
// Error represents an error returned by the bunq API.
@@ -16,12 +17,12 @@ type Error struct {
1617
type Errors []Error
1718

1819
func (e Errors) Error() string {
19-
var errs []string
20-
for i := range e {
21-
errs = append(errs, e[i].ErrorDescription)
20+
errs := make([]string, len(e))
21+
for i, err := range e {
22+
errs[i] = err.ErrorDescription
2223
}
2324

24-
return fmt.Sprintf("%v", errs)
25+
return strings.Join(errs, ", ")
2526
}
2627

2728
func decodeError(r io.Reader) error {
@@ -33,7 +34,7 @@ func decodeError(r io.Reader) error {
3334
}
3435
err := json.NewDecoder(r).Decode(&apiError)
3536
if err != nil {
36-
return fmt.Errorf("bunq: could not decode errors from json: %v", err)
37+
return fmt.Errorf("could not decode errors from json: %v", err)
3738
}
3839

3940
var errors Errors

0 commit comments

Comments
 (0)