Skip to content

Simplify chat error class fallback and replace icon if/else chain with lookup - #1088

Merged
BenjaminMichaelis merged 3 commits into
mainfrom
copilot/simplify-error-message-return
May 13, 2026
Merged

Simplify chat error class fallback and replace icon if/else chain with lookup#1088
BenjaminMichaelis merged 3 commits into
mainfrom
copilot/simplify-error-message-return

Conversation

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor

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

    • Keep the special rate-limit styling
    • Return error-message for all other error types via a single default path
  • Error icon mapping

    • Replace the sequential if/else chain with a lookup table
    • Preserve the existing icons for known error types
    • Keep the warning icon as the fallback for unknown types
  • Resulting helper shape

    function getErrorMessageClass(errorType) {
        if (errorType === 'rate-limit') {
            return 'rate-limit-error';
        }
        return 'error-message';
    }
    
    function getErrorIconClass(errorType) {
        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'
        };
    
        return iconClassByErrorType[errorType] || 'fas fa-exclamation-triangle';
    }

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
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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
    • Triggering command: /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)
    • Triggering command: /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
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"Multiple branches return the same value 'error-message'. Simplify by returning 'error-message' as the default and only check for 'rate-limit' to return a different class.","fixFiles":[{"filePath":"EssentialCSharp.Web/wwwroot/js/chat-module.js","diff":"diff --git a/EssentialCSharp.Web/wwwroot/js/chat-module.js b/EssentialCSharp.Web/wwwroot/js/chat-module.js\n--- a/EssentialCSharp.Web/wwwroot/js/chat-module.js\n+++ b/EssentialCSharp.Web/wwwroot/js/chat-module.js\n@@ -143,13 +143,8 @@\n     function getErrorMessageClass(errorType) {\n         if (errorType === 'rate-limit') {\n             return 'rate-limit-error';\n-        } else if (errorType === 'auth-error') {\n-            return 'error-message';\n-        } else if (errorType === 'validation-error') {\n-            return 'error-message';\n-        } else {\n-            return 'error-message';\n         }\n+        return 'error-message';\n     }\n \n     function getErrorIconClass(errorType) {\n"}]},{"message":"This function uses a long if-else chain. Consider replacing with a switch statement or an object lookup for improved readability and maintainability.","fixFiles":[{"filePath":"EssentialCSharp.Web/wwwroot/js/chat-module.js","diff":"diff --git a/EssentialCSharp.Web/wwwroot/js/chat-module.js b/EssentialCSharp.Web/wwwroot/js/chat-module.js\n--- a/EssentialCSharp.Web/wwwroot/js/chat-module.js\n+++ b/EssentialCSharp.Web/wwwroot/js/chat-module.js\n@@ -153,19 +153,15 @@\n     }\n \n     function getErrorIconClass(errorType) {\n-        if (errorType === 'rate-limit') {\n-            return 'fas fa-clock';\n-        } else if (errorType === 'auth-error') {\n-            return 'fas fa-lock';\n-        } else if (errorType === 'validation-error') {\n-            return 'fas fa-exclamation-circle';\n-        } else if (errorType === 'network-error') {\n-            return 'fas fa-wifi';\n-        } else if (errorType === 'connection-error') {\n-            return 'fas fa-plug';\n-        } else {\n-            return 'fas fa-exclamation-triangle';\n-        }\n+        const iconClassByErrorType = {\n+            'rate-limit': 'fas fa-clock',\n+            'auth-error': 'fas fa-lock',\n+            'validation-error': 'fas fa-exclamation-circle',\n+            'network-error': 'fas fa-wifi',\n+            'connection-error': 'fas fa-plug'\n+        };\n+\n+        return iconClassByErrorType[errorType] || 'fas fa-exclamation-triangle';\n     }\n \n     async function sendChatMessage() {\n"}]}]

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>
Copilot AI changed the title [WIP] Simplify error message class logic in chat module Simplify chat error class fallback and replace icon if/else chain with lookup May 13, 2026
Copilot AI requested a review from BenjaminMichaelis May 13, 2026 07:08
@BenjaminMichaelis
BenjaminMichaelis marked this pull request as ready for review May 13, 2026 08:40
Copilot AI review requested due to automatic review settings May 13, 2026 08:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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-case rate-limit and default all other types to error-message.
  • Replaced getErrorIconClass() if/else chain with an error-type → icon-class lookup table plus a fallback icon.

Comment on lines +150 to +157
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'
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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>

Copilot AI commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

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:

  • accounts.google.com
    • Triggering command: /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=7125 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.Ful2Aq --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,16291001531285825510,12957592668062401873,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,10355399412203762007,3116280185382557107,4 --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /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 (dns block)
  • cdnjs.cloudflare.com
    • Triggering command: /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=7125 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.Ful2Aq --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,16291001531285825510,12957592668062401873,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,10355399412203762007,3116280185382557107,4 --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /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 (dns block)
  • clients2.google.com
    • Triggering command: /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=7125 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.Ful2Aq --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,16291001531285825510,12957592668062401873,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,10355399412203762007,3116280185382557107,4 --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /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 (dns block)
  • redirector.gvt1.com
    • Triggering command: /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=7125 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.Ful2Aq --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,16291001531285825510,12957592668062401873,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,10355399412203762007,3116280185382557107,4 --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /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 (dns block)
  • www.google.com
    • Triggering command: /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=7125 --enable-crash-reporter=, --noerrdialogs --user-data-dir=/tmp/org.chromium.Chromium.scoped_dir.Ful2Aq --change-stack-guard-on-fork=enable --shared-files=network_parent_dirs_pipe:100,v8_context_snapshot_data:101 --field-trial-handle=3,i,16291001531285825510,12957592668062401873,262144 --disable-features=PaintHolding --variations-seed-version --pseudonymization-salt-handle=7,i,10355399412203762007,3116280185382557107,4 --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: /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 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@BenjaminMichaelis
BenjaminMichaelis merged commit 6df05f5 into main May 13, 2026
7 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the copilot/simplify-error-message-return branch May 13, 2026 09:44
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.

3 participants