@@ -47,24 +47,33 @@ public class DispatcherUseCase implements DispatcherInPort {
4747 public void triggerDispatching () {
4848 log .info ("Starting dispatching" );
4949 for (final UseCase useCase : swimDispatcherProperties .getUseCases ()) {
50- // handle files directly in directory
51- final String dispatchPath = useCase .getDispatchPath (swimDispatcherProperties );
52- final Map <String , Throwable > errors = new HashMap <>(
53- this .processDirectory (useCase , dispatchPath , false ));
54- // handle recursive by directory
55- if (useCase .isRecursive ()) {
56- // get folders
57- final List <String > folders = fileSystemOutPort .getSubDirectories (useCase .getBucket (), dispatchPath );
58- // dispatch files per folder if not in finished folder
59- for (final String folder : folders ) {
60- if (!folder .contains (swimDispatcherProperties .getFinishedFolder ())) {
61- errors .putAll (this .processDirectory (useCase , folder , true ));
50+ final Map <String , Throwable > errors = new HashMap <>();
51+ try {
52+ // handle files directly in directory
53+ final String dispatchPath = useCase .getDispatchPath (swimDispatcherProperties );
54+ errors .putAll (this .processDirectory (useCase , dispatchPath , false ));
55+ // handle recursive by directory
56+ if (useCase .isRecursive ()) {
57+ // get folders
58+ final List <String > folders = fileSystemOutPort .getSubDirectories (useCase .getBucket (), dispatchPath );
59+ // dispatch files per folder if not in finished folder
60+ for (final String folder : folders ) {
61+ if (!folder .contains (swimDispatcherProperties .getFinishedFolder ())) {
62+ errors .putAll (this .processDirectory (useCase , folder , true ));
63+ }
6264 }
6365 }
64- }
65- // send errors
66- if (!errors .isEmpty ()) {
67- notificationOutPort .sendDispatchErrors (useCase .getMailAddresses (), useCase .getName (), errors );
66+ // send errors
67+ if (!errors .isEmpty ()) {
68+ notificationOutPort .sendDispatchErrors (useCase .getMailAddresses (), useCase .getName (), errors );
69+ }
70+ } catch (final Exception e ) {
71+ log .error ("Processing of use case {} failed" , useCase .getName (), e );
72+ final Map <String , Throwable > enrichedErrors = new HashMap <>();
73+ enrichedErrors .put ("!!! USE CASE PROCESSING !!!" , new UseCaseException (
74+ "Unexpected error during dispatching, use case was not processed completely. Error: %s" .formatted (e .getMessage ()), e ));
75+ enrichedErrors .putAll (errors );
76+ notificationOutPort .sendDispatchErrors (useCase .getMailAddresses (), useCase .getName (), enrichedErrors );
6877 }
6978 }
7079 log .info ("Finished dispatching" );
0 commit comments