@@ -203,25 +203,27 @@ public Response checkFilingForReview(
203203 return maybeParser .unwrapErrOrElseThrow ();
204204 }
205205 var parser = maybeParser .unwrapOrElseThrow ();
206- InfoCollector collector = new NeverSubmitCollector ();
207- Result <FilingInformation , FilingError > res =
208- converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
209- if (res .isErr ()) {
210- log .error ("Error on traverseInterview: {}" , res .toString ());
211- parser .close ();
212- return Response .status (400 ).entity (collector .jsonSummary ()).build ();
213- }
214- FilingInformation info = res .unwrapOrElseThrow ();
215- info .setCourtLocation (courtId );
216- Result <NullValue , FilingError > resEfm =
217- filer .checkFiling (info , tylerUser .get ().creds (), collector );
218- if (resEfm .isErr ()) {
219- log .error ("Error on checkFiling: {}" , resEfm .toString ());
220- parser .close ();
206+ try {
207+ InfoCollector collector = new NeverSubmitCollector ();
208+ Result <FilingInformation , FilingError > res =
209+ converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
210+ if (res .isErr ()) {
211+ log .error ("Error on traverseInterview: {}" , res .toString ());
212+ parser .close ();
213+ return Response .status (400 ).entity (collector .jsonSummary ()).build ();
214+ }
215+ FilingInformation info = res .unwrapOrElseThrow ();
216+ info .setCourtLocation (courtId );
217+ Result <NullValue , FilingError > resEfm =
218+ filer .checkFiling (info , tylerUser .get ().creds (), collector );
219+ if (resEfm .isErr ()) {
220+ log .error ("Error on checkFiling: {}" , resEfm .toString ());
221+ return Response .ok (collector .jsonSummary ()).build ();
222+ }
221223 return Response .ok (collector .jsonSummary ()).build ();
224+ } finally {
225+ parser .close ();
222226 }
223- parser .close ();
224- return Response .ok (collector .jsonSummary ()).build ();
225227 }
226228
227229 @ POST
@@ -255,20 +257,22 @@ public Response calculateFilingFees(
255257 return maybeParser .unwrapErrOrElseThrow ();
256258 }
257259 var parser = maybeParser .unwrapOrElseThrow ();
258- log .trace ("Court id: {}" , courtId );
259- InfoCollector collector = new FailFastCollector ();
260- Result <FilingInformation , FilingError > res =
261- converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
262- if (res .isErr ()) {
263- log .error ("Error when calculating filing fees: {}" , res .toString ());
260+ try {
261+ log .trace ("Court id: {}" , courtId );
262+ InfoCollector collector = new FailFastCollector ();
263+ Result <FilingInformation , FilingError > res =
264+ converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
265+ if (res .isErr ()) {
266+ log .error ("Error when calculating filing fees: {}" , res .toString ());
267+ return Response .status (400 ).entity (collector .jsonSummary ()).build ();
268+ }
269+ FilingInformation info = res .unwrapOrElseThrow ();
270+ info .setCourtLocation (courtId );
271+ Result <Response , FilingError > fees = filer .getFilingFees (info , tylerUser .get ().creds ());
272+ return fees .match (err -> Response .status (400 ).entity (err .toJson ()).build (), respon -> respon );
273+ } finally {
264274 parser .close ();
265- return Response .status (400 ).entity (collector .jsonSummary ()).build ();
266275 }
267- FilingInformation info = res .unwrapOrElseThrow ();
268- info .setCourtLocation (courtId );
269- Result <Response , FilingError > fees = filer .getFilingFees (info , tylerUser .get ().creds ());
270- parser .close ();
271- return fees .match (err -> Response .status (400 ).entity (err .toJson ()).build (), respon -> respon );
272276 }
273277
274278 @ GET
@@ -303,18 +307,20 @@ public Response getServiceTypes(
303307 return maybeParser .unwrapErrOrElseThrow ();
304308 }
305309 var parser = maybeParser .unwrapOrElseThrow ();
306- InfoCollector collector = new FailFastCollector ();
307- Result <FilingInformation , FilingError > res =
308- converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
309- if (res .isErr ()) {
310+ try {
311+ InfoCollector collector = new FailFastCollector ();
312+ Result <FilingInformation , FilingError > res =
313+ converterMap .get (mediaType .toString ()).traverseInterview (allVars , parser , collector );
314+ if (res .isErr ()) {
315+ return Response .status (400 ).entity (collector .jsonSummary ()).build ();
316+ }
317+ FilingInformation info = res .unwrapOrElseThrow ();
318+ info .setCourtLocation (courtId );
319+ Result <Response , FilingError > fees = filer .getServiceTypes (info , tylerUser .get ().creds ());
320+ return fees .match (err -> Response .status (400 ).entity (err .toJson ()).build (), respon -> respon );
321+ } finally {
310322 parser .close ();
311- return Response .status (400 ).entity (collector .jsonSummary ()).build ();
312323 }
313- FilingInformation info = res .unwrapOrElseThrow ();
314- info .setCourtLocation (courtId );
315- Result <Response , FilingError > fees = filer .getServiceTypes (info , tylerUser .get ().creds ());
316- parser .close ();
317- return fees .match (err -> Response .status (400 ).entity (err .toJson ()).build (), respon -> respon );
318324 }
319325
320326 @ GET
@@ -491,25 +497,23 @@ private Result<FilingInformation, Response> parseFiling(
491497 return maybeParser .propagateErr ();
492498 }
493499 var parser = maybeParser .unwrapOrElseThrow ();
494- Result <FilingInformation , FilingError > maybeInfo =
495- converterMap .get (mediaType .toString ()).extractInformation (allVars , parser );
496- if (maybeInfo .isErr ()) {
500+ try {
501+ Result <FilingInformation , FilingError > maybeInfo =
502+ converterMap .get (mediaType .toString ()).extractInformation (allVars , parser );
503+ if (maybeInfo .isErr ()) {
504+ return Result .err (
505+ Response .status (400 ).entity (maybeInfo .unwrapErrOrElseThrow ().toJson ()).build ());
506+ }
507+ FilingInformation info = maybeInfo .unwrapOrElseThrow ();
508+ info .setCourtLocation (courtId );
509+ return Result .ok (info );
510+ } finally {
497511 try {
498512 parser .close ();
499513 } catch (Exception ex ) {
500514 log .warn ("Couldn't close parser" , ex );
501515 }
502- return Result .err (
503- Response .status (400 ).entity (maybeInfo .unwrapErrOrElseThrow ().toJson ()).build ());
504- }
505- FilingInformation info = maybeInfo .unwrapOrElseThrow ();
506- info .setCourtLocation (courtId );
507- try {
508- parser .close ();
509- } catch (Exception ex ) {
510- log .warn ("Couldn't close parser" , ex );
511516 }
512- return Result .ok (info );
513517 }
514518
515519 @ GET
0 commit comments