Reject the promise if the widget load is failed#96
Conversation
There was a problem hiding this comment.
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?: Functionproperty toUserbackOptionsinterface - 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: () => { |
There was a problem hiding this comment.
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.
| on_init_error: () => { | |
| on_init_error: () => { | |
| UBLoadingPromise = undefined; |
| }; | ||
| return resolve(USERBACK); | ||
| }, | ||
| on_init_error: () => { |
There was a problem hiding this comment.
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.
| on_init_error: () => { | |
| on_init_error: () => { | |
| if (typeof opts?.on_init_error === 'function') { | |
| opts.on_init_error(); | |
| } |
No description provided.