Skip to content

Commit

Permalink
Cleanup in aisle 3
Browse files Browse the repository at this point in the history
  • Loading branch information
dbutenhof committed Dec 5, 2022
1 parent 2442189 commit e4b373f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
7 changes: 2 additions & 5 deletions lib/pbench/server/api/resources/query_apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,8 @@ def _call(self, method: Callable, params: ApiParams):
except UnauthorizedAccess as e:
raise APIAbort(e.http_status, str(e))
except KeyError as e:
self.logger.exception("{} problem in preprocess, missing {}", klasname, e)
raise APIAbort(
HTTPStatus.INTERNAL_SERVER_ERROR,
f"Missing expected backend data: {str(e)!r}",
)
self.logger.error("{} problem in preprocess, missing {}", klasname, e)
raise APIInternalError(self.logger, "Missing expected backend data")
try:
# prepare payload for Elasticsearch query
es_request = self.assemble(params, context)
Expand Down
14 changes: 4 additions & 10 deletions lib/pbench/server/api/resources/query_apis/datasets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from http import HTTPStatus
from logging import Logger
from typing import AnyStr, List, Union

from pbench.server import JSON, PbenchServerConfig
from pbench.server.api.resources import (
API_AUTHORIZATION,
APIAbort,
APIInternalError,
ApiParams,
ApiSchema,
ParamType,
Expand Down Expand Up @@ -129,17 +128,12 @@ def get_index(self, dataset: Dataset, root_index_name: AnyStr) -> AnyStr:
try:
index_map = Metadata.getvalue(dataset=dataset, key=Metadata.INDEX_MAP)
except MetadataError as exc:
self.logger.error("{}", str(exc))
raise APIAbort(
HTTPStatus.INTERNAL_SERVER_ERROR,
f"Required metadata missing: {str(exc)!r}",
)
self.logger.error("{}", exc)
raise APIInternalError(self.logger, "Required metadata missing")

if index_map is None:
self.logger.error("Index map metadata has no value")
raise APIAbort(
HTTPStatus.INTERNAL_SERVER_ERROR, "Required metadata missing"
)
raise APIInternalError(self.logger, "Required metadata missing")

index_keys = [key for key in index_map if root_index_name in key]
indices = ",".join(index_keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,5 @@ def _get(self, params: ApiParams, request: Request) -> Response:
# construct response object
return jsonify(result)
except TemplateNotFound as e:
self.logger.error("{}", str(e))
self.logger.error("{}", e)
raise APIInternalError(self.logger, "Unexpected template error")
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def assemble(self, params: ApiParams, context: CONTEXT) -> JSON:
try:
mappings = self.get_mappings(document)
except TemplateNotFound as e:
self.logger.error("{}", str(e))
self.logger.error("{}", e)
raise APIInternalError(self.logger, "Unexpected template error")

result = self.get_aggregatable_fields(mappings)
Expand Down Expand Up @@ -281,7 +281,7 @@ def assemble(self, params: ApiParams, context: CONTEXT) -> JSON:
try:
mappings = self.get_mappings(document)
except TemplateNotFound as e:
self.logger.error("{}", str(e))
self.logger.error("{}", e)
raise APIInternalError(self.logger, "Unexpected template error")

# Prepare list of filters to apply for ES query
Expand Down

0 comments on commit e4b373f

Please sign in to comment.