From 5edbb5c08eb70d173c2879fc64a35076191e52f7 Mon Sep 17 00:00:00 2001 From: Marwan Zaarab <99911676+marwan37@users.noreply.github.com> Date: Wed, 3 Apr 2024 18:16:33 -0500 Subject: [PATCH] Update ErrorTreeItem.ts for better readability Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/views/activityBar/common/ErrorTreeItem.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/views/activityBar/common/ErrorTreeItem.ts b/src/views/activityBar/common/ErrorTreeItem.ts index 86bf4c14..b619bbad 100644 --- a/src/views/activityBar/common/ErrorTreeItem.ts +++ b/src/views/activityBar/common/ErrorTreeItem.ts @@ -54,26 +54,20 @@ export const createErrorItem = (error: any): TreeItem[] => { */ export const createAuthErrorItem = (errorMessage: string): ErrorTreeItem[] => { const parts = errorMessage.split(':').map(part => part.trim()); - - let generalError = ''; - let detailedError = ''; - let actionSuggestion = ''; + let [generalError, detailedError, actionSuggestion] = ['', '', '']; if (parts.length > 2) { - generalError = parts[0]; // "Failed to retrieve pipeline runs" - detailedError = parts[1] + ': ' + (parts[2].split('.')[0] || '').trim(); // "Authentication error: error decoding access token" - actionSuggestion = (parts[2].split('. ')[1] || '').trim(); // "You may need to rerun zenml connect" + generalError = parts[0]; + detailedError = `${parts[1]}: ${(parts[2].split('.')[0] || '').trim()}`; + actionSuggestion = (parts[2].split('. ')[1] || '').trim(); } const errorItems: ErrorTreeItem[] = []; - if (detailedError) { errorItems.push(new ErrorTreeItem(parts[1], detailedError.split(':')[1].trim())); } - if (actionSuggestion) { errorItems.push(new ErrorTreeItem(actionSuggestion, '')); } - return errorItems; };