export const formatError = (error: unknown, message: string = ''): string => {
    const prefix = message ? `${message}: ` : '';
    const suffix = (error && typeof error === 'object' ) ? (('stack' in error) ? `\n${error.stack}` : '') : '';

    const errorMessage = formatErrorMessage(error).trim();

    return `${prefix}${errorMessage}${suffix}`;
}

export const formatErrorMessage = (error: unknown): string => {
    if (error && typeof error === 'object' && 'message' in error) {
        return `${error.message}`;
    } else if (error && typeof error === 'object' && 'data' in error) {
        return `${error.data}`;
    } else if (error) {
        return error.toString();
    } else {
        return 'Unknown error';
    }
}