LegacyFlowRunnerImpl implements LegacyFlowRunner { protected RunFlowResponse handleFlowRunnerException (Exception e) { ObjectMapper objectMapper = new ObjectMapper(); RunFlowResponse resp = null; if(e instanceof FailedRequestException && StringUtils.containsIgnoreCase(((FailedRequestException) e).getFailedRequest().getStatus(), "Plugin error")){ try { resp = objectMapper.readValue(((FailedRequestException)e).getFailedRequest().getMessage(), RunFlowResponse.class); } catch (IOException ex) { throw new RuntimeException("Unexpected IO error while parsing exception from running flow; original exception: " + e.getMessage()); } } else{ throw new RuntimeException(e); } return resp; } LegacyFlowRunnerImpl(HubConfig hubConfig); protected  LegacyFlowRunnerImpl(); @Override LegacyFlowRunner withFlow(LegacyFlow flow); @Override LegacyFlowRunner withBatchSize(int batchSize); @Override LegacyFlowRunner withThreadCount(int threadCount); @Override LegacyFlowRunner withSourceClient(DatabaseClient stagingClient); @Override LegacyFlowRunner withDestinationDatabase(String destinationDatabase); @Override LegacyFlowRunner withStopOnFailure(boolean stopOnFailure); @Override LegacyFlowRunner withOptions(Map<String, Object> options); @Override LegacyFlowRunner onItemComplete(LegacyFlowItemCompleteListener listener); @Override LegacyFlowRunner onItemFailed(LegacyFlowItemFailureListener listener); @Override LegacyFlowRunner onStatusChanged(LegacyFlowStatusListener listener); @Override LegacyFlowRunner onFinished(LegacyFlowFinishedListener listener); @Override void awaitCompletion(); @Override void awaitCompletion(long timeout, TimeUnit unit); @Override JobTicket run();  }
@Test public void testFlowRunnerException() { RunFlowResponse resp = null; LegacyFlowRunnerImpl fr = new LegacyFlowRunnerImpl(); FailedRequest req = new FailedRequest(); req.setMessageCode("RESTAPI-SRVEXERR"); req.setMessageString("{\n" + "\t\"totalCount\": 3,\n" + "\t\"errorCount\": 3,\n" + "\t\"completedItems\": [],\n" + "\t\"failedItems\": [\"/10287.json\", \"/10310.json\", \"/10328.json\"],\n" + "\t\"errors\": []\n" + "}"); req.setStatusString("Plugin error"); resp = fr.handleFlowRunnerException(new FailedRequestException("failed to apply resource at resources/mlFlow: Plugin error", req)); Assertions.assertEquals(3, resp.errorCount); Assertions.assertEquals(3, resp.totalCount); }
@Test public void testFlowRunnerExceptionWithoutPluginError() { RunFlowResponse resp = null; LegacyFlowRunnerImpl fr = new LegacyFlowRunnerImpl(); FailedRequest req = new FailedRequest(); req.setMessageCode("RESTAPI-SRVEXERR"); req.setMessageString("{\n" + "\t\"totalCount\": 3,\n" + "\t\"errorCount\": 3,\n" + "\t\"completedItems\": [],\n" + "\t\"failedItems\": [\"/10287.json\", \"/10310.json\", \"/10328.json\"],\n" + "\t\"errors\": []\n" + "}"); req.setStatusString("Failed"); try { fr.handleFlowRunnerException(new FailedRequestException("Not a 'Plugin error' exception", req)); } catch (Exception e) { Assertions.assertTrue(e instanceof RuntimeException); e.printStackTrace(); System.out.println(e.getMessage()); Assertions.assertTrue(e.getMessage().contains("com.marklogic.client.FailedRequestException: Local message: Not a 'Plugin error' exception")); } }