Skip to content

Commit

Permalink
Checking for Collection exists.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysrevans3 committed Apr 8, 2024
1 parent 3c1248e commit b6e2e76
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions stac_generator/plugins/outputs/stac_fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def item(self, data: dict) -> None:
urljoin(self.api_url, f"collections/{collection}/items"),
json=data,
verify=self.verify,
timeout=180,
)

if response.status_code == 404:
Expand Down Expand Up @@ -108,11 +109,14 @@ def item(self, data: dict) -> None:
),
json=data,
verify=self.verify,
timeout=180,
)

if response.status_code != 200:
LOGGER.warning(
f"FastAPI Output Update failed with status code: {response.status_code} and response text: {response.text}"
"FastAPI Output Item update failed with status code: %s and response text: %s",
response.status_code,
response.text,
)

elif response.status_code != 200:
Expand All @@ -131,7 +135,29 @@ def collection(self, data: dict) -> None:
timeout=180,
)

if response.status_code != 200:
if response.status_code == 409:
response_json = response.json()

if (
response_json["description"]
== f"Collection {data['id']} already exists"
):
response = requests.put(
urljoin(self.api_url, "collections"),
# urljoin(self.api_url, f"collections/{data['id']}"),
json=data,
verify=self.verify,
timeout=180,
)

if response.status_code != 200:
LOGGER.warning(
"FastAPI Output Collection update failed with status code: %s and response text: %s",
response.status_code,
response.text,
)

elif response.status_code != 200:
LOGGER.warning(
"FastAPI Output failed to post to STAC Fastapi collections endpoint returned status code: %s and response text: %s request data: %s",
response.status_code,
Expand Down

0 comments on commit b6e2e76

Please sign in to comment.