-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from Scalr/27-bug-failed-to-load-log-typeerror…
…-fetch-failed-while-first-login-to-scalr-extension Add better error handling and reduce api call on create vscode session
- Loading branch information
Showing
8 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ErrorDocument } from './types.gen'; | ||
import * as vscode from 'vscode'; | ||
|
||
export function getErrorMessage(error: unknown): string { | ||
if (typeof error === 'string') { | ||
return error; | ||
} | ||
|
||
if (typeof error === 'object' && error !== null && 'errors' in error) { | ||
const errorDocument = error as ErrorDocument; | ||
if (errorDocument.errors) { | ||
//TODO:ape add the titile to the error type in scalr api | ||
//@ts-expect-error the title is not exposed in the error type but it is in the api | ||
return errorDocument.errors.map((e) => e.title || e.detail).join('\n'); | ||
} | ||
} | ||
|
||
return 'Unknown error'; | ||
} | ||
|
||
export function showErrorMessage(error: unknown, prefix: string | undefined = undefined): void { | ||
if (prefix) { | ||
vscode.window.showErrorMessage(prefix + '. ' + getErrorMessage(error)); | ||
return; | ||
} | ||
|
||
vscode.window.showErrorMessage(getErrorMessage(error)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters