Source:
<code>private void throwExceptionOnErrorStatus(String url, int statusCode, JsonElement node, String message) { if (Strings.isNullOrEmpty(message)) { if (node != null && node.getAsJsonObject().get("message") != null) { message = node.getAsJsonObject().get("message").getAsString(); } else { message = "There has been an error on the server"; } } if (statusCode == 412) { UserSessionInfo session = null; if (node != null) { session = RestUtils.GSON.fromJson(node, UserSessionInfo.class); } throw new ConsentRequiredException("Consent required.", url, session); } String type = (node != null) ? node.getAsJsonObject().get("type").getAsString() : "Unknown"; switch(type) { case "NotAuthenticatedException": <START> throw new NotAuthenticatedException(message, url); <END> case "UnauthorizedException": throw new UnauthorizedException(message, url); case "EntityNotFoundException": throw new EntityNotFoundException(message, url); case "EndpointNotFoundException": throw new EndpointNotFoundException(message, url); case "UnsupportedVersionException": throw new UnsupportedVersionException(message, url); case "EntityAlreadyExistsException": throw new EntityAlreadyExistsException(message, url); case "ConcurrentModificationException": throw new ConcurrentModificationException(message, url); case "ConstraintViolationException": throw new ConstraintViolationException(message, url); case "PublishedSurveyException": throw new PublishedSurveyException(message, url); case "InvalidEntityException": Map<String, List<String>> errors = Maps.newHashMap(); if (node != null && node.getAsJsonObject().get("errors") != null) { errors = RestUtils.GSON.fromJson(node.getAsJsonObject().get("errors"), ERRORS_MAP_TYPE_TOKEN); } throw new InvalidEntityException(message, errors, url); case "NotImplementedException": throw new NotImplementedException(message, url); case "BadRequestException": throw new BadRequestException(message, url); default: throw new BridgeSDKException(message, statusCode, url); } }</code><technical_language>Also, work Reflection handle of cases. way, need a big switch statement convert exception name exception class identical constructor invocations</technical_language>

Target:
private void throwExceptionOnErrorStatus(String url, int statusCode, JsonElement node, String message) { if (Strings.isNullOrEmpty(message)) { if (node != null && node.getAsJsonObject().get("message") != null) { message = node.getAsJsonObject().get("message").getAsString(); } else { message = "There has been an error on the server"; } } if (statusCode == 412) { UserSessionInfo session = null; if (node != null) { session = RestUtils.GSON.fromJson(node, UserSessionInfo.class); } throw new ConsentRequiredException("Consent required.", url, session); } String type = (node != null) ? node.getAsJsonObject().get("type").getAsString() : "Unknown"; if ("InvalidEntityException".equals(type)) { Map<String, List<String>> errors = Maps.newHashMap(); if (node != null && node.getAsJsonObject().get("errors") != null) { errors = RestUtils.GSON.fromJson(node.getAsJsonObject().get("errors"), ERRORS_MAP_TYPE_TOKEN); } throw new InvalidEntityException(message, errors, url); } throwBridgeExceptionIfItExists(type, message, url); throw new BridgeSDKException(message, statusCode, url); }