summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSatya Rohith <me@satyarohith.com>2021-10-10 15:44:45 +0530
committerGitHub <noreply@github.com>2021-10-10 15:44:45 +0530
commit25771b3d9b36a7262d42809bfbb5497ed8057780 (patch)
tree47a41c2cb3b32b094ea9ca833c8bc28a3808ccb0
parent66804d26f3c12849c7fef9c7a27cb7beff5e3709 (diff)
feat(ext/net): relevant errors for resolveDns (#12370)
-rw-r--r--cli/tests/testdata/resolve_dns.ts4
-rw-r--r--cli/tests/testdata/resolve_dns.ts.out2
-rw-r--r--ext/net/ops.rs15
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();