Skip to content

Instantly share code, notes, and snippets.

@Yummy-Yums
Created June 7, 2024 12:15
Show Gist options
  • Save Yummy-Yums/0dae0f93066b3bc012b8e1a3dd581072 to your computer and use it in GitHub Desktop.
Save Yummy-Yums/0dae0f93066b3bc012b8e1a3dd581072 to your computer and use it in GitHub Desktop.
Promise Workaround
export async function checkWhetherURLExists(url: URL) {
try{
const response = await fetch(url.origin);
return response.status == 200
} catch(error){
return new Response("something went wronger")
}
}
export class UrlHandler implements URLInterface {
validateURLWell(url: string){
const parsedURL = this.parseURL(url) as URL
const urlCheck = checkWhetherURLExists(parsedURL)
urlCheck
.then((value) => {
console.log("it's a" + value)
if(typeof value == "boolean" ){
return true ? value == true : false
} else if ( value instanceof Response){
}
})
.then((value) => {
return value
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment