1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00
metamask-extension/shared/modules/error.ts

25 lines
655 B
TypeScript
Raw Permalink Normal View History

import log from 'loglevel';
/**
* Type guard for determining whether the given value is an error object with a
* `message` property, such as an instance of Error.
*
* TODO: Remove once this becomes available at @metamask/utils
*
* @param error - The object to check.
* @returns True or false, depending on the result.
*/
export function isErrorWithMessage(
error: unknown,
): error is { message: string } {
return typeof error === 'object' && error !== null && 'message' in error;
}
export function logErrorWithMessage(error: unknown) {
if (isErrorWithMessage(error)) {
log.error(error.message);
} else {
log.error(error);
}
}