Generalize snackWithFallback for remaining error handlers#3890
Generalize snackWithFallback for remaining error handlers#3890
Conversation
Replace direct snackError({messageTxt: error.message, ...}) calls with
snackWithFallback(snackError, error, {...}) to support structured error
display (ProblemDetailError, business errors) consistently across the
codebase.
Signed-off-by: Florent MILLOT <millotflo@gmail.com>
Signed-off-by: Florent MILLOT <75525996+flomillot@users.noreply.github.com>
📝 WalkthroughWalkthroughThe PR replaces direct error notification calls with a fallback-based error handling mechanism across multiple components. All instances of Changes
Suggested Reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/network/gs-map-equipments.ts (1)
60-98: LGTM – consider extracting the duplicated.catchhandler.All eight
.catchhandlers ininitEquipmentsandreloadImpactedSubstationsEquipmentsnow follow the same 4-line pattern (console.error+ conditionalsnackWithFallbackwith the sameheaderId). Behavior is correct and consistent with the PR objective. As an optional follow-up, extracting a privatehandleLoadError = (error) => { ... }method would remove the duplication.♻️ Optional refactor
+ private handleLoadError = (error: unknown) => { + console.error((error as Error)?.message); + if (this.errHandler) { + snackWithFallback(this.errHandler, error, { headerId: 'MapEquipmentsLoadError' }); + } + };Then each
.catch((error) => { ... })becomes.catch(this.handleLoadError).Also applies to: 166-189
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/network/gs-map-equipments.ts` around lines 60 - 98, Extract the duplicated four-line .catch handler into a single private method (e.g., handleLoadError = (error) => { ... }) and replace each .catch((error) => { ... }) in initEquipments and reloadImpactedSubstationsEquipments with .catch(this.handleLoadError); the method should call console.error(error.message) and, if this.errHandler exists, call snackWithFallback(this.errHandler, error, { headerId: 'MapEquipmentsLoadError' }) to preserve current behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/components/network/gs-map-equipments.ts`:
- Around line 60-98: Extract the duplicated four-line .catch handler into a
single private method (e.g., handleLoadError = (error) => { ... }) and replace
each .catch((error) => { ... }) in initEquipments and
reloadImpactedSubstationsEquipments with .catch(this.handleLoadError); the
method should call console.error(error.message) and, if this.errHandler exists,
call snackWithFallback(this.errHandler, error, { headerId:
'MapEquipmentsLoadError' }) to preserve current behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: da995a2e-b34d-49f4-aa86-3dbfc85a9b50
📒 Files selected for processing (5)
src/components/dialogs/parameters/use-get-pcc-min-parameters.tssrc/components/grid-layout/cards/diagrams/singleLineDiagram/single-line-diagram-content.tsxsrc/components/network/gs-map-equipments.tssrc/components/results/pccmin/pcc-min-export-button.tsxsrc/components/study-container.jsx
|



Summary
snackError({messageTxt: error.message, ...})patterns withsnackWithFallback(snackError, error, {...})to support structured error display (ProblemDetailError, business errors)study-container.jsx,single-line-diagram-content.tsx,gs-map-equipments.ts,pcc-min-export-button.tsx,use-get-pcc-min-parameters.tsNote:
globalFiltersMiddleware.tswas not converted because Redux middlewares cannot access React hooks (useSnackMessage). An architectural bridge would be needed to exposesnackErrorto middleware.