Skip to content

Commit 2b359f6

Browse files
committed
Switch to http exception.
1 parent 7368d8d commit 2b359f6

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/database_logic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import attr
1212
from elasticsearch_dsl import Q, Search
13+
from fastapi import HTTPException
1314
from starlette.requests import Request
1415

1516
from elasticsearch import exceptions, helpers # type: ignore
@@ -987,8 +988,8 @@ async def json_patch_item(
987988
)
988989

989990
except exceptions.BadRequestError as exc:
990-
raise exceptions.BadRequestError(
991-
exc.info["error"]["caused_by"]["to_string"]
991+
raise HTTPException(
992+
status_code=400, detail=exc.info["error"]["caused_by"]["to_string"]
992993
) from exc
993994

994995
item = await self.get_one_item(collection_id, item_id)

stac_fastapi/opensearch/stac_fastapi/opensearch/database_logic.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Any, Dict, Iterable, List, Optional, Protocol, Tuple, Type, Union
1010

1111
import attr
12+
from fastapi import HTTPException
1213
from opensearchpy import exceptions, helpers
1314
from opensearchpy.exceptions import TransportError
1415
from opensearchpy.helpers.query import Q
@@ -1019,8 +1020,8 @@ async def json_patch_item(
10191020
)
10201021

10211022
except exceptions.BadRequestError as exc:
1022-
raise exceptions.BadRequestError(
1023-
exc.info["error"]["caused_by"]["to_string"]
1023+
raise HTTPException(
1024+
status_code=400, detail=exc.info["error"]["caused_by"]["to_string"]
10241025
) from exc
10251026

10261027
item = await self.get_one_item(collection_id, item_id)

stac_fastapi/tests/clients/test_elasticsearch.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
1-
import os
21
import uuid
32
from copy import deepcopy
43
from typing import Callable
54

65
import pytest
6+
from fastapi import HTTPException
77
from stac_pydantic import Item, api
88

9-
if os.getenv("BACKEND", "elasticsearch").lower() == "opensearch":
10-
from elasticsearch import exceptions
11-
else:
12-
from opensearchpy import exceptions
13-
149
from stac_fastapi.extensions.third_party.bulk_transactions import Items
1510
from stac_fastapi.types.errors import ConflictError, NotFoundError
1611
from stac_fastapi.types.stac import PatchAddReplaceTest, PatchMoveCopy, PatchRemove
@@ -441,7 +436,7 @@ async def test_json_patch_item_test_wrong_value(ctx, core_client, txn_client):
441436
),
442437
]
443438

444-
with pytest.raises(exceptions.BadRequestError):
439+
with pytest.raises(HTTPException):
445440

446441
await txn_client.json_patch_item(
447442
collection_id=collection_id,
@@ -464,7 +459,7 @@ async def test_json_patch_item_replace_property_does_not_exists(
464459
),
465460
]
466461

467-
with pytest.raises(exceptions.BadRequestError):
462+
with pytest.raises(HTTPException):
468463

469464
await txn_client.json_patch_item(
470465
collection_id=collection_id,
@@ -485,7 +480,7 @@ async def test_json_patch_item_remove_property_does_not_exists(
485480
PatchRemove.model_validate({"op": "remove", "path": "properties.foo"}),
486481
]
487482

488-
with pytest.raises(exceptions.BadRequestError):
483+
with pytest.raises(HTTPException):
489484

490485
await txn_client.json_patch_item(
491486
collection_id=collection_id,
@@ -508,7 +503,7 @@ async def test_json_patch_item_move_property_does_not_exists(
508503
),
509504
]
510505

511-
with pytest.raises(exceptions.BadRequestError):
506+
with pytest.raises(HTTPException):
512507

513508
await txn_client.json_patch_item(
514509
collection_id=collection_id,
@@ -531,7 +526,7 @@ async def test_json_patch_item_copy_property_does_not_exists(
531526
),
532527
]
533528

534-
with pytest.raises(exceptions.BadRequestError):
529+
with pytest.raises(HTTPException):
535530

536531
await txn_client.json_patch_item(
537532
collection_id=collection_id,

0 commit comments

Comments
 (0)