Skip to content

Commit 6df05f5

Browse files
authored
Simplify chat error class fallback and replace icon if/else chain with lookup (#1088)
1 parent c75ea17 commit 6df05f5

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

EssentialCSharp.Web/wwwroot/js/chat-module.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import DOMPurify from "dompurify";
33
import { marked } from "marked";
44
import { ref, nextTick, watch, onMounted, onUnmounted } from "vue";
55

6+
const errorIconClassByType = {
7+
'rate-limit': 'fas fa-clock',
8+
'auth-error': 'fas fa-lock',
9+
'validation-error': 'fas fa-exclamation-circle',
10+
'network-error': 'fas fa-wifi',
11+
'connection-error': 'fas fa-plug'
12+
};
13+
614
export function useChatWidget() {
715
// Authentication state
816
const isAuthenticated = ref(window.IS_AUTHENTICATED || false);
@@ -143,29 +151,12 @@ export function useChatWidget() {
143151
function getErrorMessageClass(errorType) {
144152
if (errorType === 'rate-limit') {
145153
return 'rate-limit-error';
146-
} else if (errorType === 'auth-error') {
147-
return 'error-message';
148-
} else if (errorType === 'validation-error') {
149-
return 'error-message';
150-
} else {
151-
return 'error-message';
152154
}
155+
return 'error-message';
153156
}
154157

155158
function getErrorIconClass(errorType) {
156-
if (errorType === 'rate-limit') {
157-
return 'fas fa-clock';
158-
} else if (errorType === 'auth-error') {
159-
return 'fas fa-lock';
160-
} else if (errorType === 'validation-error') {
161-
return 'fas fa-exclamation-circle';
162-
} else if (errorType === 'network-error') {
163-
return 'fas fa-wifi';
164-
} else if (errorType === 'connection-error') {
165-
return 'fas fa-plug';
166-
} else {
167-
return 'fas fa-exclamation-triangle';
168-
}
159+
return errorIconClassByType[errorType] || 'fas fa-exclamation-triangle';
169160
}
170161

171162
async function sendChatMessage() {

0 commit comments

Comments
 (0)