Skip to content

Commit 706de24

Browse files
Show more context on registration errors
I.e. "Invalid USA Zip code"
1 parent fd05e55 commit 706de24

3 files changed

Lines changed: 59 additions & 48 deletions

File tree

proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/ecf4/Ecf4Helper.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,12 @@ public static Response makeResponse(
275275
return mapTylerCodesToHttp(checkErrors(resp.getError()), defaultRespFunc);
276276
}
277277

278-
/** Returns true on errors from the ECF side of the API. They work the same as the Tyler ones. */
279278
public record Error(String code, String text) {}
280279

280+
/**
281+
* Returns the error type on errors from the ECF side of the API. They work the same as the Tyler
282+
* ones.
283+
*/
281284
public static Optional<Error> checkError(
282285
oasis.names.tc.legalxml_courtfiling.schema.xsd.commontypes_4.ErrorType error) {
283286
var errCode = error.getErrorCode();

proxyserver/src/main/java/edu/suffolk/litlab/efsp/server/services/AdminUserService.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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. */

proxyserver/src/main/java/edu/suffolk/litlab/efsp/tyler/TylerErrorCodes.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import jakarta.ws.rs.core.Response;
44
import java.util.List;
55
import java.util.Map;
6+
import java.util.Optional;
67
import java.util.function.Supplier;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
@@ -64,41 +65,47 @@ public class TylerErrorCodes {
6465
);
6566

6667
public static boolean hasError(BaseResponseType resp) {
67-
return checkErrors(resp.getError());
68+
return checkErrors(resp.getError()).isPresent();
6869
}
6970

7071
public static Response makeResponse(BaseResponseType resp, Supplier<Response> defaultRespFunc) {
71-
return TylerErrorCodes.mapTylerCodesToHttp(resp.getError(), defaultRespFunc);
72+
return TylerErrorCodes.mapTylerCodesToHttp(checkErrors(resp.getError()), defaultRespFunc);
7273
}
7374

75+
public record Error(String code, String text) {}
76+
7477
/** Returns true on errors from the Tyler / Admin side of the API. */
75-
public static boolean checkErrors(tyler.efm.latest.services.schema.common.ErrorType error) {
78+
public static Optional<Error> checkErrors(
79+
tyler.efm.latest.services.schema.common.ErrorType error) {
7680
var code = error.getErrorCode();
7781
if (code.equals("0")) {
78-
return false;
82+
return Optional.empty();
7983
}
8084

8185
if (nonAlertingCodes.contains(code)) {
8286
log.warn("Got a non-urgent erroring response from Tyler: {}: {}", code, error.getErrorText());
8387
} else {
8488
log.error("Error from Tyler!: {}: {}", code, error.getErrorText());
8589
}
86-
return true;
90+
return Optional.of(new Error(error.getErrorCode(), error.getErrorText()));
91+
}
92+
93+
public static boolean shouldLogError(Error error) {
94+
return !nonAlertingCodes.contains(error.code);
8795
}
8896

8997
public static Response mapTylerCodesToHttp(
90-
tyler.efm.latest.services.schema.common.ErrorType error, Supplier<Response> defaultRespFunc) {
91-
if (!checkErrors(error)) {
98+
Optional<Error> maybeError, Supplier<Response> defaultRespFunc) {
99+
if (!maybeError.isPresent()) {
92100
return defaultRespFunc.get();
93101
}
94102

95-
if (TylerErrorCodes.tylerToHttp.containsKey(error.getErrorCode())) {
96-
return Response.status(TylerErrorCodes.tylerToHttp.get(error.getErrorCode()))
97-
.entity(error.getErrorText())
98-
.build();
103+
var error = maybeError.get();
104+
if (tylerToHttp.containsKey(error.code)) {
105+
return Response.status(tylerToHttp.get(error.code)).entity(error.text).build();
99106
}
100107

101108
// 422 as semantic issues covers most of the error codes
102-
return Response.status(422).entity(error.getErrorText()).build();
109+
return Response.status(422).entity(error.text).build();
103110
}
104111
}

0 commit comments

Comments
 (0)