Skip to content

Reject the promise if the widget load is failed#96

Merged
lee-userback merged 3 commits intodevelopfrom
aliu/add-promise-return
Nov 18, 2025
Merged

Reject the promise if the widget load is failed#96
lee-userback merged 3 commits intodevelopfrom
aliu/add-promise-return

Conversation

@hunterdes
Copy link
Collaborator

No description provided.

@hunterdes hunterdes linked an issue Nov 17, 2025 that may be closed by this pull request
@lee-userback lee-userback merged commit 8a5eb56 into develop Nov 18, 2025
4 checks passed
@hunterdes hunterdes requested a review from Copilot November 25, 2025 04:55
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds error handling functionality for widget initialization failures by introducing a new on_init_error callback option. When the Userback widget fails to load due to invalid server responses, the promise is now properly rejected with a meaningful error message.

Key Changes

  • Added on_init_error?: Function property to UserbackOptions interface
  • Implemented error rejection in widget loader when initialization fails
  • Added ESLint suppression comments for console statements in Angular example

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
widget-js/widget.ts Added on_init_error callback property and implementation to reject promise on widget load failure
examples/next-app/src/app/page.tsx Formatting change - consolidated Image component props to single line
examples/angular/src/main.ts Added eslint-disable comments for console.log and console.error statements
examples/angular/src/app/child.component.ts Added no-unused-vars to existing eslint-disable comment for constructor parameter
docs/*.html Auto-generated documentation updates reflecting line number changes from new interface property

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

};
return resolve(USERBACK);
},
on_init_error: () => {
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

When on_init_error is triggered and the promise is rejected, the UBLoadingPromise should be reset to undefined to allow retry attempts. Currently, if initialization fails, subsequent calls to UserbackWidgetLoader will return the same rejected promise (line 161), preventing any retry logic.

Suggested change
on_init_error: () => {
on_init_error: () => {
UBLoadingPromise = undefined;

Copilot uses AI. Check for mistakes.
};
return resolve(USERBACK);
},
on_init_error: () => {
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

The on_init_error callback is added to the options but doesn't call the user-provided opts?.on_init_error function if it exists. This means users who provide their own error handler won't have it invoked when an initialization error occurs. Consider calling opts?.on_init_error?.() before or after rejecting the promise.

Suggested change
on_init_error: () => {
on_init_error: () => {
if (typeof opts?.on_init_error === 'function') {
opts.on_init_error();
}

Copilot uses AI. Check for mistakes.
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.

Error Handling and Messaging Improvements

3 participants