From c544dc28c549821fadc345eacf8d711f435a1282 Mon Sep 17 00:00:00 2001 From: michelkaporin Date: Thu, 23 Dec 2021 17:14:34 +0100 Subject: [PATCH] fix: getIpFamily not detecting IPv6 support --- src/constants.ts | 1 + src/http.ts | 7 +++++-- src/needle.ts | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index f572b60b..d350dc6b 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -48,6 +48,7 @@ export const NETWORK_ERRORS = { ECONNRESET: ErrorCodes.connectionRefused, ENETUNREACH: ErrorCodes.connectionRefused, ENOTFOUND: ErrorCodes.dnsNotFound, + EADDRNOTAVAIL: ErrorCodes.dnsNotFound, // happens when DNS cannot resolve the IPv6 }; export const DEFAULT_ERROR_MESSAGES: { [P in ErrorCodes]: string } = { diff --git a/src/http.ts b/src/http.ts index 8d96fcd8..c6bf57d0 100644 --- a/src/http.ts +++ b/src/http.ts @@ -5,7 +5,7 @@ import { ErrorCodes, GenericErrorTypes, DEFAULT_ERROR_MESSAGES, MAX_RETRY_ATTEMP import { BundleFiles, SupportedFiles } from './interfaces/files.interface'; import { AnalysisResult } from './interfaces/analysis-result.interface'; -import { makeRequest, Payload } from './needle'; +import { FailedResponse, makeRequest, Payload } from './needle'; import { AnalysisOptions, AnalysisContext } from './interfaces/analysis-options.interface'; type ResultSuccess = { type: 'success'; value: T }; @@ -99,7 +99,10 @@ export async function getIpFamily(authHost: string): Promise { }, 0, ); - return res.success ? family : undefined; + + const ipv6Incompatible = (res).errorCode == ErrorCodes.dnsNotFound; + + return ipv6Incompatible ? undefined : family; } type CheckSessionErrorCodes = GenericErrorTypes | ErrorCodes.unauthorizedUser | ErrorCodes.loginInProgress; diff --git a/src/needle.ts b/src/needle.ts index 54876f6f..05dc3ef4 100644 --- a/src/needle.ts +++ b/src/needle.ts @@ -44,7 +44,7 @@ interface SuccessResponse { success: true; body: T; } -type FailedResponse = { +export type FailedResponse = { success: false; errorCode: number; };