1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-11 16:42:21 -05:00

feat(ext/net): relevant errors for resolveDns (#12370)

This commit is contained in:
Satya Rohith 2021-10-10 15:44:45 +05:30 committed by GitHub
parent 66804d26f3
commit 25771b3d9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 4 deletions

View file

@ -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`);
}

View file

@ -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

View file

@ -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();