From 667ec6015952d531b3cbd62d962c75a14ebeb0e6 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sun, 4 Apr 2021 11:41:49 +0800 Subject: [PATCH] client: handle DNS response headers properly --- src/client.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index 442c6f7..f96a4d1 100644 --- a/src/client.rs +++ b/src/client.rs @@ -3,7 +3,7 @@ use domain_core::bits::message_builder::MessageBuilder; use domain_core::bits::question::Question; use domain_core::bits::record::Record; use domain_core::bits::{ParsedDname, SectionBuilder}; -use domain_core::iana::Opcode; +use domain_core::iana::{Opcode, Rcode}; use domain_core::rdata::AllRecordData; use js_sys::{ArrayBuffer, Uint8Array}; use wasm_bindgen_futures::JsFuture; @@ -30,7 +30,12 @@ impl Client { let msg = Self::build_query(questions)?; let upstream = self.select_upstream(); let resp = Self::do_query(&upstream, msg).await?; - Self::extract_answers(resp) + + match resp.header().rcode() { + Rcode::NoError => Self::extract_answers(resp), + Rcode::NXDomain => Ok(Vec::new()), + rcode => Err(format!("Server error: {}", rcode)) + } } pub async fn query_with_retry(