@@ -188,8 +188,7 @@ public Response getNotificationPrefs(@Context HttpHeaders httpHeaders) {
188188
189189 NotificationPreferencesResponseType notifResp = port .get ().getNotificationPreferences ();
190190
191- return TylerErrorCodes .mapTylerCodesToHttp (
192- notifResp .getError (), () -> Response .ok (notifResp .getNotification ()).build ());
191+ return makeResponse (notifResp , () -> Response .ok (notifResp .getNotification ()).build ());
193192 }
194193
195194 @ PATCH
@@ -209,7 +208,7 @@ public Response updateNotificationPrefs(
209208 }
210209
211210 BaseResponseType notifResp = port .get ().updateNotificationPreferences (updateNotif );
212- return TylerErrorCodes . mapTylerCodesToHttp (notifResp . getError () , () -> Response .ok ().build ());
211+ return makeResponse (notifResp , () -> Response .ok ().build ());
213212 }
214213
215214 @ POST
@@ -289,11 +288,7 @@ public Response resetPassword(
289288 resetReq .setEmail (params .email );
290289 resetReq .setPassword (params .newPassword );
291290 ResetPasswordResponseType resp = port .get ().resetUserPassword (resetReq );
292- return TylerErrorCodes .mapTylerCodesToHttp (
293- resp .getError (),
294- () -> {
295- return Response .ok ("\" " + resp .getPasswordHash () + "\" " ).build ();
296- });
291+ return makeResponse (resp , () -> Response .ok ("\" " + resp .getPasswordHash () + "\" " ).build ());
297292 }
298293
299294 public static class SetPasswordParams {
@@ -319,11 +314,8 @@ public Response setPassword(@Context HttpHeaders httpHeaders, SetPasswordParams
319314 change .setPasswordQuestion ("" );
320315 change .setPasswordAnswer ("" );
321316 ChangePasswordResponseType resp = port .get ().changePassword (change );
322- return TylerErrorCodes .mapTylerCodesToHttp (
323- resp .getError (),
324- () -> {
325- return Response .ok ("\" " + resp .getPasswordHash () + "\" " ).build ();
326- });
317+ return TylerErrorCodes .makeResponse (
318+ resp , () -> Response .ok ("\" " + resp .getPasswordHash () + "\" " ).build ());
327319 }
328320
329321 @ POST
@@ -340,11 +332,7 @@ public Response selfResetPassword(@Context HttpHeaders httpHeaders, String email
340332 ResetPasswordResponseType resp = port .get ().resetPassword (reset );
341333 // TODO(brycew-later): why would we reply with the password hash? They still shouldn't be able
342334 // to log in?
343- return TylerErrorCodes .mapTylerCodesToHttp (
344- resp .getError (),
345- () -> {
346- return Response .ok ("\" " + resp .getPasswordHash () + "\" " ).build ();
347- });
335+ return makeResponse (resp , () -> Response .ok ("\" " + resp .getPasswordHash () + "\" " ).build ());
348336 }
349337
350338 /**
@@ -378,8 +366,7 @@ public Response getUser(@Context HttpHeaders httpHeaders, @PathParam("id") Strin
378366 userGetter = (req ) -> port .get ().getUser (getUserReq );
379367 }
380368 var userRes = userGetter .apply (getUserReq );
381- return TylerErrorCodes .mapTylerCodesToHttp (
382- userRes .getError (), () -> Response .ok (userRes .getUser ()).build ());
369+ return makeResponse (userRes , () -> Response .ok (userRes .getUser ()).build ());
383370 }
384371
385372 @ GET
@@ -402,8 +389,7 @@ public Response getUserList(
402389 var req = new GetUserListRequest ();
403390 req .setPaging (paging );
404391 UserListResponseType resp = port .get ().getUserList (req );
405- return TylerErrorCodes .mapTylerCodesToHttp (
406- resp .getError (), () -> Response .ok (resp .getUser ()).build ());
392+ return makeResponse (resp , () -> Response .ok (resp .getUser ()).build ());
407393 }
408394
409395 @ PATCH
@@ -418,13 +404,13 @@ public Response updateUser(@Context HttpHeaders httpHeaders, UserType updatedUse
418404 GetUserRequestType getUserReq = new GetUserRequestType ();
419405 getUserReq .setUserID (httpHeaders .getHeaderString (TylerLogin .getHeaderId (jurisdiction )));
420406 GetUserResponseType userRes = port .get ().getUser (getUserReq );
421- if (TylerErrorCodes .checkErrors (userRes .getError ())) {
407+ if (TylerErrorCodes .checkErrors (userRes .getError ()). isPresent () ) {
422408 return Response .status (401 , userRes .getError ().getErrorText ()).build ();
423409 }
424410
425411 UpdateUserRequestType updateReq = updateUser (userRes .getUser (), updatedUser );
426412 UpdateUserResponseType updateResp = port .get ().updateUser (updateReq );
427- if (TylerErrorCodes .checkErrors (updateResp .getError ())) {
413+ if (TylerErrorCodes .checkErrors (updateResp .getError ()). isPresent () ) {
428414 return Response .status (401 ).entity (updateResp .getError ().getErrorText ()).build ();
429415 }
430416
@@ -452,13 +438,13 @@ public Response updateUserById(
452438 GetUserRequestType getUserReq = new GetUserRequestType ();
453439 getUserReq .setUserID (id );
454440 GetUserResponseType userRes = port .get ().getUser (getUserReq );
455- if (TylerErrorCodes .checkErrors (userRes .getError ())) {
441+ if (TylerErrorCodes .checkErrors (userRes .getError ()). isPresent () ) {
456442 return Response .status (401 , userRes .getError ().getErrorText ()).build ();
457443 }
458444
459445 UpdateUserRequestType updateReq = updateUser (userRes .getUser (), updatedUser );
460446 UpdateUserResponseType updateResp = port .get ().updateUser (updateReq );
461- if (TylerErrorCodes .checkErrors (updateResp .getError ())) {
447+ if (TylerErrorCodes .checkErrors (updateResp .getError ()). isPresent () ) {
462448 return Response .status (401 ).entity (updateResp .getError ().getErrorText ()).build ();
463449 }
464450
@@ -504,8 +490,7 @@ public Response getRoles(@Context HttpHeaders httpHeaders, @PathParam("id") Stri
504490 GetUserRequestType getUserReq = new GetUserRequestType ();
505491 getUserReq .setUserID (id );
506492 GetUserResponseType userRes = port .get ().getUser (getUserReq );
507- return TylerErrorCodes .mapTylerCodesToHttp (
508- userRes .getError (), () -> Response .ok (userRes .getUser ().getRole ()).build ());
493+ return makeResponse (userRes , () -> Response .ok (userRes .getUser ().getRole ()).build ());
509494 }
510495
511496 /**
@@ -533,7 +518,7 @@ public Response addRoles(
533518 addRole .setUserID (id );
534519 // TODO(brycew-later): this won't be consistent if it fails part way through?
535520 BaseResponseType resp = port .get ().addUserRole (addRole );
536- if (TylerErrorCodes .checkErrors (resp .getError ())) {
521+ if (TylerErrorCodes .checkErrors (resp .getError ()). isPresent () ) {
537522 return Response .status (401 ).entity (resp .getError ().getErrorText ()).build ();
538523 }
539524 }
@@ -569,7 +554,7 @@ public Response removeRoles(
569554 rmRole .setUserID (id );
570555 // TODO(brycew-later): this won't be consistent if it fails part way through?
571556 BaseResponseType resp = port .get ().removeUserRole (rmRole );
572- if (TylerErrorCodes .checkErrors (resp .getError ())) {
557+ if (TylerErrorCodes .checkErrors (resp .getError ()). isPresent () ) {
573558 return Response .status (401 ).entity (resp .getError ().getErrorText ()).build ();
574559 }
575560 }
@@ -681,10 +666,27 @@ record Required(String val, String msg) {}
681666 + regResp .getFirmID ()
682667 + " and user id: "
683668 + regResp .getUserID ());
684- if (!TylerErrorCodes .checkErrors (regResp .getError ())) {
669+ var error = TylerErrorCodes .checkErrors (regResp .getError ());
670+ if (error .isPresent ()) {
671+ logTylerErrorsWithContext (error .get (), req );
672+ return makeResponse (regResp , () -> Response .ok (regResp ).build ());
673+ } else {
685674 return Response .created (URI .create (regResp .getUserID ())).entity (regResp ).build ();
686675 }
687- return makeResponse (regResp , () -> Response .ok (regResp ).build ());
676+ }
677+
678+ private void logTylerErrorsWithContext (TylerErrorCodes .Error error , RegistrationRequestType req ) {
679+ String errContext =
680+ switch (error .code ()) {
681+ case "230" -> "Zip code: %s" .formatted (req .getZipCode ());
682+ default -> "No context for %s" .formatted (error .code ());
683+ };
684+ String message = "Error message from Tyler: {}. Context: {}" ;
685+ if (TylerErrorCodes .shouldLogError (error )) {
686+ log .error (message , error , errContext );
687+ } else {
688+ log .warn (message , error , errContext );
689+ }
688690 }
689691
690692 /**
@@ -706,7 +708,7 @@ public Response removeUser(@Context HttpHeaders httpHeaders, @PathParam("id") St
706708 RemoveUserRequestType rmUser = new RemoveUserRequestType ();
707709 rmUser .setUserID (id );
708710 BaseResponseType resp = port .get ().removeUser (rmUser );
709- return TylerErrorCodes . mapTylerCodesToHttp (resp . getError () , () -> Response .ok ().build ());
711+ return makeResponse (resp , () -> Response .ok ().build ());
710712 }
711713
712714 @ GET
@@ -720,8 +722,7 @@ public Response getNotificationPreferenceList(@Context HttpHeaders httpHeaders)
720722 }
721723
722724 NotificationPreferencesListResponseType resp = port .get ().getNotificationPreferencesList ();
723- return TylerErrorCodes .mapTylerCodesToHttp (
724- resp .getError (), () -> Response .ok (resp .getNotificationListItem ()).build ());
725+ return makeResponse (resp , () -> Response .ok (resp .getNotificationListItem ()).build ());
725726 }
726727
727728 /** Default needsSoapHeader to True: most ops need Tyler Authentication in the SOAP header. */
0 commit comments