diff options
-rw-r--r-- | cli/tests/testdata/resolve_dns.ts | 4 | ||||
-rw-r--r-- | cli/tests/testdata/resolve_dns.ts.out | 2 | ||||
-rw-r--r-- | ext/net/ops.rs | 15 |
3 files changed, 17 insertions, 4 deletions
diff --git a/cli/tests/testdata/resolve_dns.ts b/cli/tests/testdata/resolve_dns.ts index d765e0536..e4a50f7dc 100644 --- a/cli/tests/testdata/resolve_dns.ts +++ b/cli/tests/testdata/resolve_dns.ts @@ -37,6 +37,6 @@ console.log(JSON.stringify(txt)); try { await Deno.resolveDns("not-found-example.com", "A", nameServer); -} catch (_e) { - console.log("Error thrown for not-found-example.com"); +} catch (e) { + console.log(`Error ${e.name} thrown for not-found-example.com`); } diff --git a/cli/tests/testdata/resolve_dns.ts.out b/cli/tests/testdata/resolve_dns.ts.out index 78381e6c6..8b378ce71 100644 --- a/cli/tests/testdata/resolve_dns.ts.out +++ b/cli/tests/testdata/resolve_dns.ts.out @@ -14,4 +14,4 @@ SRV [{"priority":0,"weight":100,"port":1234,"target":"srv.com."}] TXT [["foo","bar"]] -Error thrown for not-found-example.com +Error NotFound thrown for not-found-example.com diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 7019a9b1f..43a562e0f 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -35,6 +35,7 @@ use trust_dns_proto::rr::record_type::RecordType; use trust_dns_resolver::config::NameServerConfigGroup; use trust_dns_resolver::config::ResolverConfig; use trust_dns_resolver::config::ResolverOpts; +use trust_dns_resolver::error::ResolveErrorKind; use trust_dns_resolver::system_conf; use trust_dns_resolver::AsyncResolver; @@ -630,7 +631,19 @@ where let results = resolver .lookup(query, record_type, Default::default()) .await - .map_err(|e| generic_error(format!("{}", e)))? + .map_err(|e| { + let message = format!("{}", e); + match e.kind() { + ResolveErrorKind::NoRecordsFound { .. } => { + custom_error("NotFound", message) + } + ResolveErrorKind::Message("No connections available") => { + custom_error("NotConnected", message) + } + ResolveErrorKind::Timeout => custom_error("TimedOut", message), + _ => generic_error(message), + } + })? .iter() .filter_map(rdata_to_return_record(record_type)) .collect(); |