diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-27 20:15:36 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-27 20:23:14 -0300 |
| commit | 47c822d0d5e690092617b6170972917058a6d45d (patch) | |
| tree | 583ce076573d29a60dc8453df7089022458b7303 /errors.go | |
| parent | 323d9a8422f06676d25cdf890c06962b260cb8aa (diff) | |
| download | go-3eb0ccf1ed0c0e3cd9cdbd0fc5862a13733f816f.tar.gz | |
A 404 that only says "not found" is correct and useless. The CEP that
fails is almost never random: it is someone who knows the city and
guessed the number, and the classic guess is the -000 that 957
municipalities never received.
The API now names the municipality on the 404, so surface it as
Error.Faixa instead of throwing the body away.
Diffstat (limited to 'errors.go')
| -rw-r--r-- | errors.go | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -84,6 +84,22 @@ type Error struct { // the client's own cap is applied to it. RetryAfter time.Duration + // Faixa is the municipality the CEP would belong to, set only on + // [ErrCEPNotFound] and only when the API could name one. It is nil for + // every other kind, and also for a CEP that falls in a numeric band the + // Correios never handed to any municipality. + // + // It turns "this CEP does not exist" into something the caller can act + // on: the city is right, the number is not. + // + // var cerr *cepis.Error + // if errors.As(err, &cerr) && cerr.Faixa != nil { + // fmt.Printf("did you mean somewhere in %s/%s? (%s to %s)\n", + // cerr.Faixa.Localidade, cerr.Faixa.UF, + // cerr.Faixa.CEPIni, cerr.Faixa.CEPFim) + // } + Faixa *Faixa + // Message describes the failure without the "cepis: " prefix. Message string |