public RunResponse restart(RunRequest runRequest) {
    RunResponse runResponse = restartRecursively(runRequest);
    if (runResponse.getStatus() == RunResponse.Status.NON_TERMINAL_ERROR) {
      LOG.error(
          "workflow instance {} does not support restart action as it is in a non-terminal status [{}]",
          runRequest.getWorkflowIdentity(),
          runResponse.getTimelineEvent().getMessage());
      throw new MaestroBadRequestException(
          Collections.emptyList(),
          "workflow instance %s does not support restart action as it is in a non-terminal status [%s]",
          runRequest.getWorkflowIdentity(),
          runResponse.getTimelineEvent().getMessage());
    }
    return runResponse;
  }
@Test
  public void testRestartNonTerminalError() {
    WorkflowInstance wfInstance = new WorkflowInstance();
    wfInstance.setInitiator(new ManualInitiator());
    wfInstance.setStatus(WorkflowInstance.Status.IN_PROGRESS);
    wfInstance.setWorkflowInstanceId(10L);
    wfInstance.setWorkflowRunId(1L);
    wfInstance.setWorkflowId("test-workflow");
    wfInstance.setRuntimeWorkflow(Workflow.builder().build());
    RunRequest request =
        RunRequest.builder()
            .initiator(new ManualInitiator())
            .currentPolicy(RunPolicy.RESTART_FROM_BEGINNING)
            .restartConfig(
                RestartConfig.builder().addRestartNode("test-workflow", 1L, null).build())
            .build();
    when(instanceDao.getWorkflowInstance("test-workflow", 1L, Constants.LATEST_INSTANCE_RUN, true))
        .thenReturn(wfInstance);

    AssertHelper.assertThrows(
        "Cannot restart a non-terminal state instance",
        MaestroBadRequestException.class,
        "workflow instance [test-workflow][1] does not support restart action as it is in a non-terminal status [IN_PROGRESS]",
        () -> actionHandler.restart(request));
  }