diff options
Diffstat (limited to 'source/cepis/exception.d')
| -rw-r--r-- | source/cepis/exception.d | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/source/cepis/exception.d b/source/cepis/exception.d index 9b77449..d34f725 100644 --- a/source/cepis/exception.d +++ b/source/cepis/exception.d @@ -26,6 +26,8 @@ module cepis.exception; import core.time : Duration; import std.typecons : Nullable; +import cepis.model : Faixa; + @safe: /** @@ -74,17 +76,36 @@ class InvalidCepException : CepisException } } -/// The CEP is well-formed but does not exist in the DNE database. +/** + * The CEP is well-formed but does not exist in the DNE database. + * + * When the API can say which municipality the number $(I would) have belonged + * to, that arrives in $(D faixa) and the message names it. It is $(B context + * for the error), not a result: the CEP still does not exist. + */ class CepNotFoundException : CepisException { /// The CEP that was looked up, unmasked. const string cep; + /** + * The municipality whose range the CEP falls in, or null. + * + * Null whenever the API sent no usable `faixa` — including the ordinary + * case of a CEP in a band no municipality owns, where the API $(B omits) + * the field rather than sending null. Either way the lookup is still a + * not-found; see $(D Faixa) before showing any of it to a user. + */ + const Nullable!Faixa faixa; + /// - this(string cep, string file = __FILE__, size_t line = __LINE__) pure nothrow + this(string cep, Nullable!Faixa faixa = Nullable!Faixa.init, + string file = __FILE__, size_t line = __LINE__) pure nothrow { - super("CEP " ~ cep ~ " does not exist in the DNE database", file, line); + super("CEP " ~ cep ~ " does not exist in the DNE database" ~ (faixa.isNull + ? "" : " (that range belongs to " ~ faixa.get.localidadeUf ~ ")"), file, line); this.cep = cep; + this.faixa = faixa; } } |