1717package io .superdurable .dex .controller ;
1818
1919import io .superdurable .dex .Client ;
20- import io .superdurable .dex .DexException ;
21- import io .superdurable .dex .ErrorSubStatus ;
20+ import io .superdurable .dex .exceptions . FlowAlreadyStartedException ;
21+ import io .superdurable .dex .exceptions . FlowNotActiveException ;
2222import io .superdurable .dex .workflow .shortlistcandidates .EmployerOptInFlow ;
2323import io .superdurable .dex .workflow .shortlistcandidates .EmployerOptInInput ;
2424import io .superdurable .dex .workflow .shortlistcandidates .ShortlistFlow ;
@@ -62,12 +62,9 @@ public ResponseEntity<String> optIn(@RequestBody final Map<String, String> reque
6262 workflowId ,
6363 input ,
6464 ExampleFlows .startOptions ());
65- } catch (final DexException e ) {
66- if (e .getSubStatus () == ErrorSubStatus .FLOW_ALREADY_STARTED ) {
67- return ResponseEntity .ok (
68- String .format ("Employer %s has already opted in" , employerId ));
69- }
70- throw e ;
65+ } catch (final FlowAlreadyStartedException alreadyStarted ) {
66+ return ResponseEntity .ok (
67+ String .format ("Employer %s has already opted in" , employerId ));
7168 }
7269
7370 return ResponseEntity .ok (String .format ("Started workflowId: %s" , workflowId ));
@@ -81,12 +78,9 @@ public ResponseEntity<String> optOut(@RequestBody final Map<String, String> requ
8178 client .newRpcStub (EmployerOptInFlow .class , workflowId );
8279 try {
8380 client .invokeRPC (stub ::optOut );
84- } catch (final DexException e ) {
85- if (e .getSubStatus () == ErrorSubStatus .FLOW_NOT_EXISTS ) {
86- return ResponseEntity .ok (
87- String .format ("Employer %s is not in the opt-in status" , employerId ));
88- }
89- throw e ;
81+ } catch (final FlowNotActiveException inactive ) {
82+ return ResponseEntity .ok (
83+ String .format ("Employer %s is not in the opt-in status" , employerId ));
9084 }
9185 return ResponseEntity .ok (String .format ("Employer %s has opted out" , employerId ));
9286 }
@@ -118,12 +112,9 @@ public ResponseEntity<String> shortlist(@RequestBody final Map<String, String> r
118112 workflowId ,
119113 input ,
120114 ExampleFlows .startOptions ());
121- } catch (final DexException e ) {
122- if (e .getSubStatus () == ErrorSubStatus .FLOW_ALREADY_STARTED ) {
123- return ResponseEntity .ok (
124- String .format ("Already running workflowId: %s" , workflowId ));
125- }
126- throw e ;
115+ } catch (final FlowAlreadyStartedException alreadyStarted ) {
116+ return ResponseEntity .ok (
117+ String .format ("Already running workflowId: %s" , workflowId ));
127118 }
128119
129120 return ResponseEntity .ok (String .format ("Started workflowId: %s" , workflowId ));
@@ -138,13 +129,10 @@ public ResponseEntity<String> revokeShortlist(
138129
139130 try {
140131 client .publish (workflowId , shortlistFlow .revokeShortlist , (Void ) null );
141- } catch (final DexException e ) {
142- if (e .getSubStatus () == ErrorSubStatus .FLOW_NOT_EXISTS ) {
143- return ResponseEntity .ok (String .format (
144- "No running workflow to revoke for %s" ,
145- employerId + "-" + candidateId ));
146- }
147- throw e ;
132+ } catch (final FlowNotActiveException inactive ) {
133+ return ResponseEntity .ok (String .format (
134+ "No running workflow to revoke for %s" ,
135+ employerId + "-" + candidateId ));
148136 }
149137
150138 return ResponseEntity .ok (String .format (
@@ -160,11 +148,8 @@ public ResponseEntity<Long> getEmailSentTimestamp(
160148 final ShortlistFlow stub = client .newRpcStub (ShortlistFlow .class , workflowId );
161149 try {
162150 return ResponseEntity .ok (client .invokeRPC (stub ::getEmailSentTimestamp ));
163- } catch (final DexException e ) {
164- if (e .getSubStatus () == ErrorSubStatus .FLOW_NOT_EXISTS ) {
165- return ResponseEntity .notFound ().build ();
166- }
167- throw e ;
151+ } catch (final FlowNotActiveException inactive ) {
152+ return ResponseEntity .notFound ().build ();
168153 }
169154 }
170155}
0 commit comments