-
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 branch 'main' of github.com:penja/scalr-vscode
- Loading branch information
Showing
7 changed files
with
72 additions
and
18 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
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