Skip to content

Commit

Permalink
Merge pull request #58 from Freegle/bugfix/abort-controller_timeout_u…
Browse files Browse the repository at this point in the history
…ndefined

Update EmailValidator:
  • Loading branch information
edwh authored Dec 4, 2023
2 parents b2893ee + 52e1635 commit f1951b7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions components/EmailValidator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,23 +130,24 @@ export default {
requestGoogleDnsResolve(domain) {
const url = new URL('https://dns.google/resolve')
url.search = new URLSearchParams({ name: domain }).toString()
const abortController = new AbortController()
const timer = setTimeout(() => abortController.abort(), 10 * 1000)
return fetch(url, { signal: AbortSignal.timeout(10000) }).then(
(response) => response.json()
)
return fetch(url, { signal: abortController.signal })
.then((response) => response.json())
.finally(() => clearTimeout(timer))
},
async checkValidDomain(value) {
let isValidDomain = true
const domain = value.substring(value.indexOf('@') + 1)
let request
if (domainValidationCache.has(domain)) {
request = domainValidationCache.get(domain)
} else {
request = this.requestGoogleDnsResolve(domain)
domainValidationCache.set(domain, request)
}
try {
const request = domainValidationCache.has(domain)
? domainValidationCache.get(domain)
: this.requestGoogleDnsResolve(domain)
domainValidationCache.set(domain, request)
const { Status: status } = await request
isValidDomain = status === 0
Expand Down

0 comments on commit f1951b7

Please sign in to comment.