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:
parent
66804d26f3
commit
25771b3d9b
3 changed files with 17 additions and 4 deletions
4
cli/tests/testdata/resolve_dns.ts
vendored
4
cli/tests/testdata/resolve_dns.ts
vendored
|
@ -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`);
|
||||
}
|
||||
|
|
2
cli/tests/testdata/resolve_dns.ts.out
vendored
2
cli/tests/testdata/resolve_dns.ts.out
vendored
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue