diff options
Diffstat (limited to 'client.go')
| -rw-r--r-- | client.go | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -225,11 +225,21 @@ func (c *Client) Lookup(ctx context.Context, cep string) (*Address, error) { switch resp.status { case http.StatusNotFound: + // The body may name the municipality the CEP would fall in; when it + // does, say so in the message too, because most callers only ever + // print the error. + faixa := decodeFaixa(resp.body) + message := "CEP " + number + " does not exist in the DNE database" + if faixa != nil { + message += " (range of " + faixa.Localidade + "/" + faixa.UF + + ", which goes from " + faixa.CEPIni + " to " + faixa.CEPFim + ")" + } return nil, &Error{ Kind: ErrCEPNotFound, CEP: number, Status: resp.status, - Message: "CEP " + number + " does not exist in the DNE database", + Faixa: faixa, + Message: message, } case http.StatusBadRequest: return nil, &Error{ |