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

Handle all external APIs failure gracefully #146

Merged
merged 6 commits into from
Oct 11, 2024

Conversation

Jemiiah
Copy link
Contributor

@Jemiiah Jemiiah commented Sep 25, 2024

PR Fixes:

  • 1 use try catch for all api
  • 2 return fallback data on failure
  • 3 log/toast failure

Resolves #111

Checklist before requesting a review

  • [✅] I have performed a self-review of my code
  • [✅] I assure there is no similar/duplicate pull request regarding same issue
  • [✅] My PR passes all checks (build, lint, formatting, etc)

@Jemiiah
Copy link
Contributor Author

Jemiiah commented Sep 26, 2024

@akiraonstarknet @EjembiEmmanuel pr ready to be merged

@akiraonstarknet
Copy link
Contributor

@Jemiiah Hey, I think a cleaner approach would be to have a standard function to wrap all fetch calls and handle failures in it. We can even add retries within such functions, would allow us to handle things better.

Example:

async function myFetch(method: 'GET' | 'POST', url: string, data: any, errorToastMsg?: string) {
    const MAX_RETRY = 3;
    let retry = 0;
    while(retry < MAX_RETRY) {
       try {
          // use above data to do a fetch and return result
       } catch(err) {
          if (retry < MAX_RETRY) {
            await new Promise((res) => setTimeout(res, 2000)) // waiting 2s
            retry += 1;
          } else {
            // failure above max retries
            // return any fall back data or show toast as per situation. Feel free to add more input params if required to generalise
          }
       }
   }
}

@akiraonstarknet
Copy link
Contributor

@Jemiiah checked code on a high level, looks ok. Will clone, test a bit and then merge. Allow me 1-2 days. Thanks

@akiraonstarknet akiraonstarknet merged commit e933c99 into strkfarm:dev Oct 11, 2024
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Handle all external APIs failure gracefully
3 participants