diff --git a/lib/import/Importer.js b/lib/import/Importer.js index c552a7d5..19915ace 100644 --- a/lib/import/Importer.js +++ b/lib/import/Importer.js @@ -17,38 +17,42 @@ function importBpmnDiagram(diagram, definitions, done) { var importer = diagram.get('bpmnImporter'), eventBus = diagram.get('eventBus'); - var warnings = []; + var error, + warnings = []; - var visitor = { + function parse(definitions) { - root: function(element) { - return importer.add(element); - }, + var visitor = { - element: function(element, parentShape) { - return importer.add(element, parentShape); - }, + root: function(element) { + return importer.add(element); + }, - error: function(message, context) { - warnings.push({ message: message, context: context }); - } - }; + element: function(element, parentShape) { + return importer.add(element, parentShape); + }, - var walker = new BpmnTreeWalker(visitor); + error: function(message, context) { + warnings.push({ message: message, context: context }); + } + }; - try { - eventBus.fire('import.start'); + var walker = new BpmnTreeWalker(visitor); // import walker.handleDefinitions(definitions); - - eventBus.fire('import.success', { warnings: warnings }); - - done(null, warnings); - } catch (e) { - eventBus.fire('import.error', { error: e }); - done(e); } + + eventBus.fire('import.start'); + + try { + parse(definitions); + } catch (e) { + error = e; + } + + eventBus.fire(error ? 'import.error' : 'import.success', { error: error, warnings: warnings }); + done(error, warnings); } module.exports.importBpmnDiagram = importBpmnDiagram; \ No newline at end of file