Skip to content

Commit

Permalink
Fixes #1238: convert internal-only ErrorCodes into `ErrorCode.SERVE…
Browse files Browse the repository at this point in the history
…R_INTERNAL_ERROR`
  • Loading branch information
tatu-at-datastax committed Jul 3, 2024
1 parent c74a1e2 commit 0987348
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.stargate.sgv2.jsonapi.api.model.command.clause.filter;

import io.stargate.sgv2.jsonapi.exception.ErrorCode;
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
import io.stargate.sgv2.jsonapi.service.operation.model.impl.DBFilterBase;
import io.stargate.sgv2.jsonapi.service.shredding.model.DocumentId;
import jakarta.validation.Valid;
Expand Down Expand Up @@ -139,9 +138,8 @@ private static JsonLiteral<?> getLiteral(Object value) {
if (value instanceof UUID || value instanceof ObjectId) {
return new JsonLiteral<>(value.toString(), JsonType.STRING);
}
throw new JsonApiException(
ErrorCode.FILTER_UNRESOLVABLE,
String.format("Unsupported filter value type %s", value.getClass()));
throw ErrorCode.SERVER_INTERNAL_ERROR.toApiException(
"Unsupported filter value type `%s`", value.getClass().getName());
}

public List<FilterOperation<?>> match(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public enum ErrorCode {
EMBEDDING_PROVIDER_TIMEOUT("The Embedding Provider timed out"),
EMBEDDING_PROVIDER_UNEXPECTED_RESPONSE("The Embedding Provider returned an unexpected response"),

FILTER_UNRESOLVABLE("Unable to resolve the filter"),

FILTER_MULTIPLE_ID_FILTER(
"Cannot have more than one _id equals filter clause: use $in operator instead"),

Expand Down Expand Up @@ -66,8 +64,6 @@ public enum ErrorCode {

SHRED_BAD_DOCID_EMPTY_STRING("Bad value for '_id' property: empty String not allowed"),

SHRED_INTERNAL_NO_PATH("Internal: path being built does not point to a property or element"),

SHRED_UNRECOGNIZED_NODE_TYPE("Unrecognized JSON node type in input document"),

SHRED_DOC_LIMIT_VIOLATION("Document size limitation violated"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.stargate.sgv2.jsonapi.api.model.command.Filterable;
import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.LogicalExpression;
import io.stargate.sgv2.jsonapi.exception.ErrorCode;
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
import io.stargate.sgv2.jsonapi.service.operation.model.Operation;
import io.stargate.sgv2.jsonapi.service.operation.model.impl.DBFilterBase;
import java.util.ArrayList;
Expand Down Expand Up @@ -69,8 +68,7 @@ public LogicalExpression apply(CommandContext commandContext, T command) {
.findFirst() // unwraps the Optional from the resolver function.
.orElseThrow(
() ->
new JsonApiException(
ErrorCode.FILTER_UNRESOLVABLE,
ErrorCode.SERVER_INTERNAL_ERROR.toApiException(
"Filter type not supported, unable to resolve to a filtering strategy"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants;
import io.stargate.sgv2.jsonapi.exception.ErrorCode;
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
import java.util.Objects;

/**
Expand Down Expand Up @@ -146,7 +145,8 @@ public Builder(String base) {
public Builder nestedArrayBuilder() {
// Must not be called unless we are pointing to a property or element:
if (childPath == null) {
throw new JsonApiException(ErrorCode.SHRED_INTERNAL_NO_PATH);
throw ErrorCode.SHRED_INTERNAL_NO_PATH.toApiException(
"Shredder path being built does not point to a property or element");
}
return new Builder(childPath, true);
}
Expand All @@ -155,7 +155,8 @@ public Builder nestedArrayBuilder() {
public Builder nestedObjectBuilder() {
// Must not be called unless we are pointing to a property or element:
if (childPath == null) {
throw new JsonApiException(ErrorCode.SHRED_INTERNAL_NO_PATH);
throw ErrorCode.SHRED_INTERNAL_NO_PATH.toApiException(
"Shredder path being built does not point to a property or element");
}
return new Builder(childPath, false);
}
Expand Down

0 comments on commit 0987348

Please sign in to comment.