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

feat: sync endpoint error handling #2132

Merged
merged 12 commits into from
Mar 2, 2024
Merged

feat: sync endpoint error handling #2132

merged 12 commits into from
Mar 2, 2024

Conversation

pandeymangg
Copy link
Contributor

What does this PR do?

Adds a new status field to the TJsConfig type, which indicates that the formbricks js sdk is in an error state. Its set after a sync call fails and then the initialize function checks for the error state to skip initialization

Fixes # (issue)

How should this be tested?

  • Fail the sync call, throw an error from the api route for example.
  • There should be no unnecessary sync calls

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read How we Code at Formbricks
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand bits
  • Ran pnpm build
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Formbricks Docs if changes were necessary

Copy link

vercel bot commented Feb 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
formbricks-cloud ⬜️ Ignored (Inspect) Visit Preview Mar 2, 2024 10:48am
formbricks-com ⬜️ Ignored (Inspect) Visit Preview Mar 2, 2024 10:48am

Copy link
Contributor

github-actions bot commented Feb 27, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

packages/js/src/lib/initialize.ts

Consider using a more descriptive variable name than 'e' for the error object in the catch block. This will improve the readability of your code and make it easier for others to understand.
Create Issue
See the diff
Checkout the fix

    try {
      existingConfig = config.get();
    } catch (error) {
      logger.debug("No existing configuration found.");
    }
git fetch origin && git checkout -b ReviewBot/Impro-fswczsv origin/ReviewBot/Impro-fswczsv

@formbricks formbricks deleted a comment from review-agent-prime bot Feb 27, 2024
Copy link
Member

@mattinannt mattinannt left a comment

Choose a reason for hiding this comment

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

@pandeymangg Thank you for the PR 😊💪 I changed a few things up:

  • When formbricks-js enters the error state it gets deinitialized. This makes our status management easier as formbricks-js can't be initialized and in an error state
  • The error state management doesn't happen in the sync but in the functions that use the sync. that makes it easier to handle the different cases and we don't bloat the sync function with different checks.
  • As we currently have some users sending a lot of attributes, I also removed the sync after changing an attribute.

@mattinannt mattinannt added this pull request to the merge queue Mar 2, 2024
Merged via the queue into main with commit 56f6dbe Mar 2, 2024
14 checks passed
@mattinannt mattinannt deleted the feat/js-sync-status branch March 2, 2024 10:59
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.

None yet

2 participants