private FlowExecutionException wrap(Exception e) {
if (isActive()) {
FlowSession session = getActiveSession();
String flowId = session.getDefinition().getId();
String stateId = session.getState() != null ? session.getState().getId() : null;
return new FlowExecutionException(flowId, stateId, "Exception thrown in state '" + stateId + "' of flow '"
+ flowId + "'", e);
} else {
return new FlowExecutionException(flow.getId(), null, "Exception thrown within inactive flow '"
+ flow.getId() + "'", e);
}
}