Skip to content

Commit 0eb3d9a

Browse files
oschwaldclaude
andcommitted
Convert switch statement to switch expression
Modernize the error code handling in handleErrorWithJsonBody() to use a switch expression instead of the traditional switch statement. This makes the code more concise and aligns with the style already used in ConnectionTypeResponse. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 33c09f2 commit 0eb3d9a

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/main/java/com/maxmind/geoip2/WebServiceClient.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -445,22 +445,16 @@ private static void handleErrorWithJsonBody(Map<String, String> content,
445445
}
446446

447447
switch (code) {
448-
case "IP_ADDRESS_NOT_FOUND":
449-
case "IP_ADDRESS_RESERVED":
448+
case "IP_ADDRESS_NOT_FOUND", "IP_ADDRESS_RESERVED" ->
450449
throw new AddressNotFoundException(error);
451-
case "ACCOUNT_ID_REQUIRED":
452-
case "ACCOUNT_ID_UNKNOWN":
453-
case "AUTHORIZATION_INVALID":
454-
case "LICENSE_KEY_REQUIRED":
455-
case "USER_ID_REQUIRED":
456-
case "USER_ID_UNKNOWN":
450+
case "ACCOUNT_ID_REQUIRED", "ACCOUNT_ID_UNKNOWN", "AUTHORIZATION_INVALID",
451+
"LICENSE_KEY_REQUIRED", "USER_ID_REQUIRED", "USER_ID_UNKNOWN" ->
457452
throw new AuthenticationException(error);
458-
case "INSUFFICIENT_FUNDS":
459-
case "OUT_OF_QUERIES":
453+
case "INSUFFICIENT_FUNDS", "OUT_OF_QUERIES" ->
460454
throw new OutOfQueriesException(error);
461-
case "PERMISSION_REQUIRED":
455+
case "PERMISSION_REQUIRED" ->
462456
throw new PermissionRequiredException(error);
463-
default:
457+
default ->
464458
// These should be fairly rare
465459
throw new InvalidRequestException(error, code, uri);
466460
}

0 commit comments

Comments
 (0)