// since we assume that parse errors happen on all of the shards.
for (ShardSearchFailure failure : e.shardFailures()) {
Throwable unwrapped = ExceptionsHelper.unwrapCause(failure.failure());
if (!(unwrapped instanceof SearchParseException)) {
LOG.warn("Unhandled ShardSearchFailure", e);
return new BadRequestException();
}
Throwable rootCause = ((SearchParseException) unwrapped).getRootCause();
if (rootCause instanceof ParseException) {
Token currentToken = ((ParseException) rootCause).currentToken;
SearchResponse sr = new SearchResponse();
sr.query = query;
sr.error = new QueryParseError();
if (currentToken == null) {
LOG.warn("No position/token available for ParseException.");
} else {
// scan for first usable token with position information
while (currentToken != null && sr.error.beginLine == 0) {
sr.error.beginColumn = currentToken.beginColumn;
sr.error.beginLine = currentToken.beginLine;
sr.error.endColumn = currentToken.endColumn;
sr.error.endLine = currentToken.endLine;
currentToken = currentToken.next;
}
}
return new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(json(sr)).build());
} else if(rootCause instanceof NumberFormatException) {
final SearchResponse sr = new SearchResponse();
sr.query = query;
sr.genericError = new GenericError();
sr.genericError.exceptionName = rootCause.getClass().getCanonicalName();
sr.genericError.message = rootCause.getMessage();
return new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(json(sr)).build());
} else {
LOG.info("Root cause of SearchParseException has unexpected, generic type!" + rootCause.getClass());
final SearchResponse sr = new SearchResponse();
sr.query = query;
sr.genericError = new GenericError();
sr.genericError.exceptionName = rootCause.getClass().getCanonicalName();
sr.genericError.message = rootCause.getMessage();
return new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity(json(sr)).build());
}
}
return new BadRequestException();
}