lionelbarrow/braintree-go — pull request #7 by lionelbarrow (2013-10-25 04:22:41+00:00)
Title: Field specific errors

This is addresses https://github.com/lionelbarrow/braintree-go/issues/5

### API

Basically you can say:

```go

result, err := gateway.Create(tx)
err.For("Transaction").On("Base")
```
=> A list of errors on the base of the transaction, e.g. "Amount is required"

You can go deeper:

```go
result, err := gateway.Create(tx)
err.For("Transaction").For("CreditCard").On("Number")
```
=> A list of errors specific to the credit card number, e.g. "Number is invalid"

### Implementation

I wrote a series of baby struct types that form a hierarchy that matches the error XML sent down by Braintree. The idea is to grow the large types until they encompass all the possible fields the API uses.

In order to get `For()` and `On()` to work, I introduce the `errorGroup` interface, which some of these baby struct types implement. `For()` always returns another `errorGroup`, while `On()` returns a list of actual errors. Hence the call chain will always be `For().For()....On()`

After merging this PR in, the framework for adding more error messages is fairly self-evident and will be done without another PR.