function formatError(error: mixed): Error {
    if (typeof error === 'object' && error != null && error instanceof Error) {
        return error;
    }
    if (typeof error === 'object' && error != null && error.message != null) {
        return new Error(error.message);
    }
    return new Error(JSON.stringify(error));
}
function formatError(error: mixed): Error {
    if (typeof error === 'object' && error != null && error instanceof Error) {
        return error;
    }
    if (typeof error === 'object' && error != null && error.message != null) {
        return new Error(error.message);
    }
    return new Error(JSON.stringify(error));
}
function formatError ( error : mixed ) : Error { if ( typeof error === 'object' && error != null && error instanceof Error ) { return error ; } if ( typeof error === 'object' && error != null && error . message != null ) { return new Error ( error . message ) ; } return new Error ( JSON . stringify ( error ) ) ; }
making sure that Error from a promise is an Error object
making sure that Error from a promise is an Error object