Skip to content

Commit

Permalink
DGS-404: Improving error messages - adding 40408 and 40409 for subjec…
Browse files Browse the repository at this point in the history
…t level compatibility and mode error (#1920)

* DGS-404: Improving error messages - adding 40408 and 40409 for subject level compatibility and mode

* fix failed tests
  • Loading branch information
Clarence97 authored Jun 21, 2021
1 parent b9002c4 commit 7d1ea5f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public class Errors {
public static final String SCHEMAVERSION_NOT_SOFT_DELETED_MESSAGE_FORMAT = "Subject '%s' Version %s was not deleted "
+ "first before being permanently deleted";
public static final int SCHEMAVERSION_NOT_SOFT_DELETED_ERROR_CODE = 40407;
public static final String SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_MESSAGE_FORMAT = "Subject '%s' does not have "
+ "subject-level compatibility configured";
public static final int SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_ERROR_CODE = 40408;
public static final String SUBJECT_LEVEL_MODE_NOT_CONFIGURED_MESSAGE_FORMAT = "Subject '%s' does not have "
+ "subject-level mode configured";
public static final int SUBJECT_LEVEL_MODE_NOT_CONFIGURED_ERROR_CODE = 40409;



Expand Down Expand Up @@ -81,12 +87,26 @@ public static RestException subjectNotSoftDeletedException(String subject) {

public static RestException schemaVersionSoftDeletedException(String subject, String version) {
return new RestNotFoundException(
String.format(SCHEMAVERSION_SOFT_DELETED_MESSAGE_FORMAT, subject, version), SCHEMAVERSION_SOFT_DELETED_ERROR_CODE);
String.format(SCHEMAVERSION_SOFT_DELETED_MESSAGE_FORMAT, subject, version),
SCHEMAVERSION_SOFT_DELETED_ERROR_CODE);
}

public static RestException schemaVersionNotSoftDeletedException(String subject, String version) {
return new RestNotFoundException(
String.format(SCHEMAVERSION_NOT_SOFT_DELETED_MESSAGE_FORMAT, subject, version), SCHEMAVERSION_NOT_SOFT_DELETED_ERROR_CODE);
String.format(SCHEMAVERSION_NOT_SOFT_DELETED_MESSAGE_FORMAT, subject, version),
SCHEMAVERSION_NOT_SOFT_DELETED_ERROR_CODE);
}

public static RestException subjectLevelCompatibilityNotConfiguredException(String subject) {
return new RestNotFoundException(
String.format(SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_MESSAGE_FORMAT, subject),
SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_ERROR_CODE);
}

public static RestException subjectLevelModeNotConfiguredException(String subject) {
return new RestNotFoundException(
String.format(SUBJECT_LEVEL_MODE_NOT_CONFIGURED_MESSAGE_FORMAT, subject),
SUBJECT_LEVEL_MODE_NOT_CONFIGURED_ERROR_CODE);
}

public static RestException versionNotFoundException(Integer id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public Config getSubjectLevelConfig(
? schemaRegistry.getCompatibilityLevelInScope(subject)
: schemaRegistry.getCompatibilityLevel(subject);
if (compatibilityLevel == null) {
throw Errors.subjectNotFoundException(subject);
throw Errors.subjectLevelCompatibilityNotConfiguredException(subject);
}
config = new Config(compatibilityLevel.name);
} catch (SchemaRegistryStoreException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ModeGetResponse getMode(
try {
Mode mode = schemaRegistry.getMode(subject);
if (mode == null) {
throw Errors.subjectNotFoundException(subject);
throw Errors.subjectLevelModeNotConfiguredException(subject);
}
return new ModeGetResponse(mode.name());
} catch (SchemaRegistryException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ public void testGetConfigNonExistentSubject() throws Exception {
+ " error code (subject not found)");
} catch (RestClientException rce) {
assertEquals("Subject not found",
Errors.SUBJECT_NOT_FOUND_ERROR_CODE,
Errors.SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_ERROR_CODE,
rce.getErrorCode());
}
}
Expand Down Expand Up @@ -1138,8 +1138,8 @@ public void testSubjectCompatibilityAfterDeletingAllVersions() throws Exception
try {
restApp.restClient.getConfig(subject);
} catch (RestClientException rce) {
assertEquals("Compatibility Level doesn't exist", Errors.SUBJECT_NOT_FOUND_ERROR_CODE, rce
.getErrorCode());
assertEquals("Compatibility Level doesn't exist",
Errors.SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_ERROR_CODE, rce.getErrorCode());
}
assertEquals("Top Compatibility Level Exists", CompatibilityLevel.FULL.name, restApp
.restClient.getConfig(null).getCompatibilityLevel());
Expand Down Expand Up @@ -1332,8 +1332,8 @@ public void testSubjectCompatibilityAfterDeletingSubject() throws Exception {
try {
restApp.restClient.getConfig(subject);
} catch (RestClientException rce) {
assertEquals("Compatibility Level doesn't exist", Errors.SUBJECT_NOT_FOUND_ERROR_CODE, rce
.getErrorCode());
assertEquals("Compatibility Level doesn't exist",
Errors.SUBJECT_LEVEL_COMPATIBILITY_NOT_CONFIGURED_ERROR_CODE, rce.getErrorCode());
}
assertEquals("Top Compatibility Level Exists", CompatibilityLevel.FULL.name, restApp
.restClient.getConfig(null).getCompatibilityLevel());
Expand Down

0 comments on commit 7d1ea5f

Please sign in to comment.