summaryrefslogtreecommitdiffstats
path: root/client.go
diff options
context:
space:
mode:
Diffstat (limited to 'client.go')
-rw-r--r--client.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/client.go b/client.go
index 53ada45..f1e3d90 100644
--- a/client.go
+++ b/client.go
@@ -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{