public static function exceptionToArray($exception, $includePrevious = false)
    {
        $array = [
            'message' => $exception->getMessage(),
            'code' => $exception->getCode(),
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'trace' => $exception->getTraceAsString(),
        ];

        if ($includePrevious) {
            $array['previous'] = self::exceptionToArray($exception->getPrevious(), true);
        }

        return $array;
    }