Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detailed err message on wrong request url #903

Merged
merged 6 commits into from
Nov 8, 2023
Merged

Conversation

nick-bisonai
Copy link
Collaborator

@nick-bisonai nick-bisonai commented Nov 8, 2023

Description

Previously, when requested cli fetcher active with wrong host and port, it returned following message
Orakl Network Fetcher [${url}] is down.

Now it checks if url is valid and returns
Invalid URL on wrong request

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist before requesting a review

  • I have performed a self-review of my code.
  • If it is a core feature, I have added thorough tests.

Deployment

  • Should publish npm package
  • Should publish Docker image

@nick-bisonai nick-bisonai self-assigned this Nov 8, 2023
@nick-bisonai nick-bisonai requested a review from a team as a code owner November 8, 2023 07:37
@nick-bisonai nick-bisonai changed the title tell between wrong url and server down detailed err message on wrong request url Nov 8, 2023
@nick-bisonai nick-bisonai linked an issue Nov 8, 2023 that may be closed by this pull request
@nick-bisonai nick-bisonai changed the title detailed err message on wrong request url Detailed err message on wrong request url Nov 8, 2023
cli/src/utils.ts Outdated
return 200 === (await axios.get(url))?.status
} catch (e) {
console.error(`Orakl Network Fetcher [${url}] is down`)
if (!(await isValidUrl(url))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just suggestion. I think we should be careful with capturing more than unnecessary amount code with try which might lead to code that is harder to read. Below, in the suggestion I move the try branch below isValidUrl which theoretically could lead to missing exception thrown by isValidUrl function, however, the function does not throw anything and only returns boolean.

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

  try {
    const response = await axios.get(url)
    if (response.status === 200) {
      return true
    } else {
      console.error(`Orakl Network Fetcher [${url}] is down. HTTP Status: ${response.status}`)
      return false
    }
  } catch (error) {
    console.error(
      `An error occurred while checking the Orakl Network Fetcher [${url}]: ${error.message}`
    )
    return false
  }
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with you, I will push again after fixing this

Copy link
Member

@martinkersner martinkersner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one small suggestion in the comment.

@nick-bisonai nick-bisonai merged commit 4e3f86f into master Nov 8, 2023
1 check passed
@nick-bisonai nick-bisonai deleted the i-879/fix/check-url branch November 8, 2023 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

orakl cli fetcher active requires detailed error message on failure
2 participants