Skip to content

Commit

Permalink
dns: do not parse JSON when response is not ok
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Jan 14, 2025
1 parent 8cb7ffd commit 1578eaf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/node/internal/internal_dns_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ export async function sendDnsRequest(
},
method: 'GET',
});
if (!response.ok) {
throw new DnsError(name, errorCodes.BADRESP, syscall);
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
json = await response.json();
} catch {
throw new DnsError(name, errorCodes.BADQUERY, syscall);
} catch (e) {
throw e instanceof DnsError
? e
: new DnsError(name, errorCodes.BADQUERY, syscall);
}

if ('error' in json) {
Expand Down

0 comments on commit 1578eaf

Please # to comment.