@Test public void handleExceptionsReturnsBadRequestForIllagelStateException() { String response = resource.handleExceptions(() -> { throw new IllegalArgumentException("error"); }, this::toError); assertThat(response, is("400 error")); }
protected <T> T handleExceptions(Supplier<T> response, BiFunction<Integer, ErrorResponse, T> error) { try { return response.get(); } catch (IllegalArgumentException e) { return error.apply(400, new ErrorResponse(e.getMessage())); } catch (NflowNotFoundException e) { return error.apply(404, new ErrorResponse(e.getMessage())); } catch (Throwable t) { return error.apply(500, new ErrorResponse(t.getMessage())); } }
ResourceBase { protected <T> T handleExceptions(Supplier<T> response, BiFunction<Integer, ErrorResponse, T> error) { try { return response.get(); } catch (IllegalArgumentException e) { return error.apply(400, new ErrorResponse(e.getMessage())); } catch (NflowNotFoundException e) { return error.apply(404, new ErrorResponse(e.getMessage())); } catch (Throwable t) { return error.apply(500, new ErrorResponse(t.getMessage())); } } }
ResourceBase { protected <T> T handleExceptions(Supplier<T> response, BiFunction<Integer, ErrorResponse, T> error) { try { return response.get(); } catch (IllegalArgumentException e) { return error.apply(400, new ErrorResponse(e.getMessage())); } catch (NflowNotFoundException e) { return error.apply(404, new ErrorResponse(e.getMessage())); } catch (Throwable t) { return error.apply(500, new ErrorResponse(t.getMessage())); } }  }
ResourceBase { protected <T> T handleExceptions(Supplier<T> response, BiFunction<Integer, ErrorResponse, T> error) { try { return response.get(); } catch (IllegalArgumentException e) { return error.apply(400, new ErrorResponse(e.getMessage())); } catch (NflowNotFoundException e) { return error.apply(404, new ErrorResponse(e.getMessage())); } catch (Throwable t) { return error.apply(500, new ErrorResponse(t.getMessage())); } }  List<ListWorkflowDefinitionResponse> listWorkflowDefinitions(final List<String> types,
      final WorkflowDefinitionService workflowDefinitions, final ListWorkflowDefinitionConverter converter,
      final WorkflowDefinitionDao workflowDefinitionDao); boolean updateWorkflowInstance(final long id,
      final UpdateWorkflowInstanceRequest req, final WorkflowInstanceFactory workflowInstanceFactory,
      final WorkflowInstanceService workflowInstances, WorkflowInstanceDao workflowInstanceDao); Stream<ListWorkflowInstanceResponse> listWorkflowInstances(final List<Long> ids, final List<String> types,
      final Long parentWorkflowId, final Long parentActionId, final List<String> states,
      final List<WorkflowInstanceStatus> statuses, final String businessKey, final String externalId, final String include,
      final Long maxResults, final Long maxActions, final WorkflowInstanceService workflowInstances,
      final ListWorkflowInstanceConverter listWorkflowConverter); ListWorkflowInstanceResponse fetchWorkflowInstance(final long id, final String include, final Long maxActions,
      final WorkflowInstanceService workflowInstances,
      final ListWorkflowInstanceConverter listWorkflowConverter); }
ResourceBase { protected <T> T handleExceptions(Supplier<T> response, BiFunction<Integer, ErrorResponse, T> error) { try { return response.get(); } catch (IllegalArgumentException e) { return error.apply(400, new ErrorResponse(e.getMessage())); } catch (NflowNotFoundException e) { return error.apply(404, new ErrorResponse(e.getMessage())); } catch (Throwable t) { return error.apply(500, new ErrorResponse(t.getMessage())); } }  List<ListWorkflowDefinitionResponse> listWorkflowDefinitions(final List<String> types,
      final WorkflowDefinitionService workflowDefinitions, final ListWorkflowDefinitionConverter converter,
      final WorkflowDefinitionDao workflowDefinitionDao); boolean updateWorkflowInstance(final long id,
      final UpdateWorkflowInstanceRequest req, final WorkflowInstanceFactory workflowInstanceFactory,
      final WorkflowInstanceService workflowInstances, WorkflowInstanceDao workflowInstanceDao); Stream<ListWorkflowInstanceResponse> listWorkflowInstances(final List<Long> ids, final List<String> types,
      final Long parentWorkflowId, final Long parentActionId, final List<String> states,
      final List<WorkflowInstanceStatus> statuses, final String businessKey, final String externalId, final String include,
      final Long maxResults, final Long maxActions, final WorkflowInstanceService workflowInstances,
      final ListWorkflowInstanceConverter listWorkflowConverter); ListWorkflowInstanceResponse fetchWorkflowInstance(final long id, final String include, final Long maxActions,
      final WorkflowInstanceService workflowInstances,
      final ListWorkflowInstanceConverter listWorkflowConverter);  }