diff options
| author | Murilo Ijanc <[email protected]> | 2026-07-27 20:31:13 -0300 |
|---|---|---|
| committer | Murilo Ijanc <[email protected]> | 2026-07-27 20:31:13 -0300 |
| commit | 42e586658b4bc39542a5311842f0040f7d29cb2b (patch) | |
| tree | bd66cccfb74235cf10449e83c4b78b38b487349d /src/Cepis/CepNotFoundException.cs | |
| parent | a2b10fd494fb389e556e40134031eb86e56e11e7 (diff) | |
| download | csharp-42e586658b4bc39542a5311842f0040f7d29cb2b.tar.gz | |
The API now hangs an optional faixa block off the 404 of GET /{cep}, and
this exposes it as CepNotFoundException.Faixa. A CEP that fails is rarely
random: it is usually someone who knows the city and guessed the number,
most often the -000 that 957 municipalities never received. Knowing where
the guess landed turns a dead-end "CEP not found" into a question worth
asking the user.
It stays an error. The block names the municipality the number would
belong to, never an address, and the lookup still throws. CepIni and
CepFim are the smallest and largest CEP that actually exist there, not the
range the Correios publish — the published start for Areal is 25845000,
exactly the CEP that fails — and the interval between them is sparse,
which is what Ceps is for.
Parsing is deliberately toothless: absent, misshapen or nameless, the
block becomes null and the caller gets the same clean not-found it got
before the field existed. A courtesy on top of a 404 must never be able to
turn it into a parse failure.
Diffstat (limited to 'src/Cepis/CepNotFoundException.cs')
| -rw-r--r-- | src/Cepis/CepNotFoundException.cs | 44 |
1 files changed, 40 insertions, 4 deletions
diff --git a/src/Cepis/CepNotFoundException.cs b/src/Cepis/CepNotFoundException.cs index ced7b16..19a4576 100644 --- a/src/Cepis/CepNotFoundException.cs +++ b/src/Cepis/CepNotFoundException.cs @@ -4,24 +4,60 @@ namespace Cepis; /// The CEP is well-formed but does not exist in the DNE database. /// </summary> /// <remarks> +/// <para> /// Retrying does not help: the answer is definitive until the next fortnightly /// database. A batch never throws this — a CEP with no address is /// <see langword="null"/> at its position instead. +/// </para> +/// <para> +/// <see cref="Faixa"/> carries the municipality the CEP would have belonged to, +/// when the API can name one. It is context for the failure and not a fallback +/// address: this is still a 404. +/// </para> /// </remarks> public sealed class CepNotFoundException : CepisException { - /// <summary>Create the exception with a message.</summary> + /// <summary>Create the exception with a message and the range, if any.</summary> /// <param name="message">what went wrong</param> - public CepNotFoundException(string message) + /// <param name="faixa"> + /// the municipality the CEP would belong to, or <see langword="null"/> when + /// the API named none + /// </param> + public CepNotFoundException(string message, Faixa? faixa = null) : base(message) { + Faixa = faixa; } - /// <summary>Create the exception with a message and an underlying cause.</summary> + /// <summary>Create the exception with a message, the range and a cause.</summary> /// <param name="message">what went wrong</param> + /// <param name="faixa">the municipality the CEP would belong to, if any</param> /// <param name="innerException">the failure underneath</param> - public CepNotFoundException(string message, Exception? innerException) + public CepNotFoundException(string message, Faixa? faixa, Exception? innerException) : base(message, innerException) { + Faixa = faixa; } + + /// <summary> + /// The municipality the CEP would have belonged to, or + /// <see langword="null"/> when there is none. + /// </summary> + /// <remarks> + /// <para> + /// <see langword="null"/> is the ordinary case for a CEP falling in a band + /// no municipality owns: the API <b>omits</b> the block rather than sending + /// a null, and an older API does not send it at all. Anything unreadable in + /// it lands here as <see langword="null"/> too — a courtesy field is not + /// worth turning a clean not-found into a parse error over. + /// </para> + /// <para> + /// It says which municipality the number <i>would</i> be in, not that any + /// address exists. Read <see cref="Cepis.Faixa"/> before using + /// <see cref="Cepis.Faixa.CepIni"/> and <see cref="Cepis.Faixa.CepFim"/>: + /// they bound the CEPs that exist there, and the range between them is + /// mostly empty. + /// </para> + /// </remarks> + public Faixa? Faixa { get; } } |