mirror of
https://github.com/pojokcodeid/nvim-lazy.git
synced 2025-06-26 18:58:51 +02:00
update
This commit is contained in:
parent
e53a643e3d
commit
1ab37bd478
209 changed files with 79957 additions and 0 deletions
33
my-snippets/laravel-blade/server/src/utils/errors.ts
Normal file
33
my-snippets/laravel-blade/server/src/utils/errors.ts
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
export function formatError(message: string, err: any): string {
|
||||
if (err instanceof Error) {
|
||||
let error = <Error>err;
|
||||
return `${message}: ${error.message}\n${error.stack}`;
|
||||
} else if (typeof err === 'string') {
|
||||
return `${message}: ${err}`;
|
||||
} else if (err) {
|
||||
return `${message}: ${err.toString()}`;
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
export function runSafe<T>(func: () => Thenable<T> | T, errorVal: T, errorMessage: string): Thenable<T> | T {
|
||||
try {
|
||||
let t = func();
|
||||
if (t instanceof Promise) {
|
||||
return t.then(void 0, e => {
|
||||
console.error(formatError(errorMessage, e));
|
||||
return errorVal;
|
||||
});
|
||||
}
|
||||
return t;
|
||||
} catch (e) {
|
||||
console.error(formatError(errorMessage, e));
|
||||
return errorVal;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue