Skip to content

Commit

Permalink
fix: handle invalid url outside try-catch statement
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Nov 8, 2023
1 parent 509c443 commit 4f6b5e9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ export async function isOraklNetworkApiHealthy() {
}

export async function isOraklFetcherHealthy(url: string) {
try {
if (!(await isValidUrl(url))) {
throw new Error('Invalid URL')
}
if (!(await isValidUrl(url))) {
console.error('Invalid URL')
return false
}

try {
const response = await axios.get(url)
if (response.status === 200) {
return true
Expand All @@ -73,13 +74,9 @@ export async function isOraklFetcherHealthy(url: string) {
return false
}
} catch (error) {
if (error.message === 'Invalid URL') {
console.error(error.message)
} else {
console.error(
`An error occurred while checking the Orakl Network Fetcher [${url}]: ${error.message}`
)
}
return false
}
}
Expand Down

0 comments on commit 4f6b5e9

Please sign in to comment.