Commit c0595fc0 authored by Sherman Yang's avatar Sherman Yang
Browse files

Fix response status code upon elastic search exception

parent 0e77e3b1
Pipeline #21192 failed with stages
in 29 minutes and 49 seconds
......@@ -16,6 +16,8 @@ package org.opengroup.osdu.search.provider.aws.provider.impl;
import com.google.common.collect.Lists;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
......@@ -45,6 +47,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
@Service
public class ScrollQueryServiceAwsImpl extends QueryBase implements IScrollQueryService {
......@@ -98,8 +102,12 @@ public class ScrollQueryServiceAwsImpl extends QueryBase implements IScrollQuery
}
} catch (AppException e) {
throw e;
} catch (ElasticsearchStatusException e) {
if (e.status() == NOT_FOUND && e.getMessage().startsWith("No search context found for id"))
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Can't find the given cursor", "The given cursor is invalid or expired", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
} catch (Exception e) {
throw new AppException(HttpServletResponse.SC_NOT_FOUND, "Invalid request", "Invalid scroll request", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
}
}
return queryResponse;
......
......@@ -16,6 +16,8 @@ package org.opengroup.osdu.search.provider.azure.provider.impl;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
......@@ -45,6 +47,8 @@ import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
@Service
public class ScrollQueryServiceImpl extends QueryBase implements IScrollQueryService {
......@@ -97,8 +101,12 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer
}
} catch (AppException e) {
throw e;
} catch (ElasticsearchStatusException e) {
if (e.status() == NOT_FOUND && e.getMessage().startsWith("No search context found for id"))
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Can't find the given cursor", "The given cursor is invalid or expired", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
} catch (Exception e) {
throw new AppException(HttpServletResponse.SC_NOT_FOUND, "Invalid request", "Invalid scroll request", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
}
}
return queryResponse;
......
......@@ -16,6 +16,8 @@ package org.opengroup.osdu.search.provider.byoc.provider.impl;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
......@@ -46,6 +48,8 @@ import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
@Service
public class ScrollQueryServiceImpl extends QueryBase implements IScrollQueryService {
......@@ -102,8 +106,12 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer
}
} catch (AppException e) {
throw e;
} catch (ElasticsearchStatusException e) {
if (e.status() == NOT_FOUND && e.getMessage().startsWith("No search context found for id"))
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Can't find the given cursor", "The given cursor is invalid or expired", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
} catch (Exception e) {
throw new AppException(HttpServletResponse.SC_NOT_FOUND, "Invalid request", "Invalid scroll request", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
}
}
return queryResponse;
......
......@@ -16,6 +16,7 @@ package org.opengroup.osdu.search.provider.gcp.provider.impl;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import org.apache.http.HttpStatus;
import org.elasticsearch.search.sort.SortBuilders;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.search.util.ElasticClientHandler;
......@@ -26,6 +27,7 @@ import org.opengroup.osdu.core.common.model.search.CursorQueryResponse;
import org.opengroup.osdu.core.common.model.search.CursorSettings;
import org.opengroup.osdu.core.common.model.search.Query;
import org.opengroup.osdu.search.provider.interfaces.IScrollQueryService;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
......@@ -45,6 +47,8 @@ import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
@Service
public class ScrollQueryServiceImpl extends QueryBase implements IScrollQueryService {
......@@ -96,8 +100,12 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer
}
} catch (AppException e) {
throw e;
} catch (ElasticsearchStatusException e) {
if (e.status() == NOT_FOUND && e.getMessage().startsWith("No search context found for id"))
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Can't find the given cursor", "The given cursor is invalid or expired", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
} catch (Exception e) {
throw new AppException(HttpServletResponse.SC_NOT_FOUND, "Invalid request", "Invalid scroll request", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
}
}
return queryResponse;
......
......@@ -26,6 +26,8 @@ import javax.inject.Inject;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.DatatypeConverter;
import org.apache.http.HttpStatus;
import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
......@@ -49,6 +51,8 @@ import org.springframework.stereotype.Service;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
@Service
public class ScrollQueryServiceImpl extends QueryBase implements IScrollQueryService {
......@@ -102,8 +106,12 @@ public class ScrollQueryServiceImpl extends QueryBase implements IScrollQuerySer
}
} catch (AppException e) {
throw e;
} catch (ElasticsearchStatusException e) {
if (e.status() == NOT_FOUND && e.getMessage().startsWith("No search context found for id"))
throw new AppException(HttpStatus.SC_BAD_REQUEST, "Can't find the given cursor", "The given cursor is invalid or expired", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
} catch (Exception e) {
throw new AppException(HttpServletResponse.SC_NOT_FOUND, "Invalid request", "Invalid scroll request", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Search error", "Error processing search request", e);
}
}
return queryResponse;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment