Simplify chat error class fallback and replace icon if/else chain with lookup - #1088
Conversation
Agent-Logs-Url: https://github.com/IntelliTect/EssentialCSharp.Web/sessions/b5b426af-ab6d-4bfd-87db-d3c82b141e4f Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR simplifies the chat widget’s UI helper logic by reducing redundant branching for error message styling and replacing a long error-icon if/else chain with a lookup, keeping the same rendered output for known error types.
Changes:
- Simplified
getErrorMessageClass()to special-caserate-limitand default all other types toerror-message. - Replaced
getErrorIconClass()if/elsechain with an error-type → icon-class lookup table plus a fallback icon.
| function getErrorIconClass(errorType) { | ||
| if (errorType === 'rate-limit') { | ||
| return 'fas fa-clock'; | ||
| } else if (errorType === 'auth-error') { | ||
| return 'fas fa-lock'; | ||
| } else if (errorType === 'validation-error') { | ||
| return 'fas fa-exclamation-circle'; | ||
| } else if (errorType === 'network-error') { | ||
| return 'fas fa-wifi'; | ||
| } else if (errorType === 'connection-error') { | ||
| return 'fas fa-plug'; | ||
| } else { | ||
| return 'fas fa-exclamation-triangle'; | ||
| } | ||
| const iconClassByErrorType = { | ||
| 'rate-limit': 'fas fa-clock', | ||
| 'auth-error': 'fas fa-lock', | ||
| 'validation-error': 'fas fa-exclamation-circle', | ||
| 'network-error': 'fas fa-wifi', | ||
| 'connection-error': 'fas fa-plug' | ||
| }; |
There was a problem hiding this comment.
Applied in a66279b. The static icon map is now hoisted to module scope, so getErrorIconClass() only does the lookup and fallback. Screenshot: https://github.com/user-attachments/assets/61ec2318-265c-4f03-aa6b-fefb6f240e12
Agent-Logs-Url: https://github.com/IntelliTect/EssentialCSharp.Web/sessions/c1e50363-bb1b-4ad1-a4aa-3c0569835125 Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
The chat widget had redundant branching in its error-style helper and a long if/else chain for error icons. This update reduces both helpers to the actual decision points while preserving the existing UI output.
Error message class handling
rate-limitstylingerror-messagefor all other error types via a single default pathError icon mapping
Resulting helper shape
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
accounts.google.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --use-angle=swiftshader-webgl --crashpad-handler-pid=8296 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.vTsROD --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,5102512708744345140,14309793493628812616,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,11190041336650348563,10014226040942773844,4 --trace-process-track-uuid=3190708989122997041(dns block)/usr/bin/chromium-browser chromium-browser --headless --disable-gpu --no-sandbox --window-size=1280,1400 --screenshot=/tmp/ecs-screenshot/chat-helper-preview.png file:///tmp/ecs-screenshot/chat-helper-preview.html 1/x64/bin/git(dns block)api.hcaptcha.com/home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests --server dotnettestcli --dotnet-test-pipe /tmp/450158852ed8446f935365f23534d325(dns block)api.pwnedpasswords.com/home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests /home/REDACTED/work/EssentialCSharp.Web/EssentialCSharp.Web/EssentialCSharp.Web.Tests/bin/Release/net10.0/EssentialCSharp.Web.Tests --server dotnettestcli --dotnet-test-pipe /tmp/450158852ed8446f935365f23534d325(dns block)cdnjs.cloudflare.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --use-angle=swiftshader-webgl --crashpad-handler-pid=8296 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.vTsROD --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,5102512708744345140,14309793493628812616,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,11190041336650348563,10014226040942773844,4 --trace-process-track-uuid=3190708989122997041(dns block)/usr/bin/chromium-browser chromium-browser --headless --disable-gpu --no-sandbox --window-size=1280,1400 --screenshot=/tmp/ecs-screenshot/chat-helper-preview.png file:///tmp/ecs-screenshot/chat-helper-preview.html 1/x64/bin/git(dns block)clients2.google.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --use-angle=swiftshader-webgl --crashpad-handler-pid=8296 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.vTsROD --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,5102512708744345140,14309793493628812616,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,11190041336650348563,10014226040942773844,4 --trace-process-track-uuid=3190708989122997041(dns block)/usr/bin/chromium-browser chromium-browser --headless --disable-gpu --no-sandbox --window-size=1280,1400 --screenshot=/tmp/ecs-screenshot/chat-helper-preview.png file:///tmp/ecs-screenshot/chat-helper-preview.html 1/x64/bin/git(dns block)redirector.gvt1.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --use-angle=swiftshader-webgl --crashpad-handler-pid=8296 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.vTsROD --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,5102512708744345140,14309793493628812616,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,11190041336650348563,10014226040942773844,4 --trace-process-track-uuid=3190708989122997041(dns block)/usr/bin/chromium-browser chromium-browser --headless --disable-gpu --no-sandbox --window-size=1280,1400 --screenshot=/tmp/ecs-screenshot/chat-helper-preview.png file:///tmp/ecs-screenshot/chat-helper-preview.html 1/x64/bin/git(dns block)www.google.com/proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=network --no-sandbox --use-angle=swiftshader-webgl --crashpad-handler-pid=8296 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.vTsROD --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,5102512708744345140,14309793493628812616,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,11190041336650348563,10014226040942773844,4 --trace-process-track-uuid=3190708989122997041(dns block)/usr/bin/chromium-browser chromium-browser --headless --disable-gpu --no-sandbox --window-size=1280,1400 --screenshot=/tmp/ecs-screenshot/chat-helper-preview.png file:///tmp/ecs-screenshot/chat-helper-preview.html 1/x64/bin/git(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt