Commit 393f690c authored by Marco Schmiedel's avatar Marco Schmiedel

fix

parent 088d522c
...@@ -54,12 +54,12 @@ blueprint = Blueprint(__name__.rsplit(".", 1)[-1], __name__) ...@@ -54,12 +54,12 @@ blueprint = Blueprint(__name__.rsplit(".", 1)[-1], __name__)
# The S3Manager instance manages file uploads to the configured S3 bucket. # The S3Manager instance manages file uploads to the configured S3 bucket.
s3_manager = S3Manager() s3_manager = S3Manager()
# The function returns a JSON error response with the supplied message and status code. # The function returns a JSON error response with the supplied message.
def _json_error(message: str, status_code: int = 502) -> Response: def _json_error(message: str) -> Response:
# A JSON payload is assembled with status "ERROR" and the provided message. # A JSON payload is assembled with status "ERROR" and the provided message.
# Always return HTTP 200 so Cloudflare never swaps in its own 5XX error page.
payload = json.dumps({"status": "ERROR", "message": message}, ensure_ascii=False) payload = json.dumps({"status": "ERROR", "message": message}, ensure_ascii=False)
# Always return HTTP 200 to prevent Cloudflare from replacing the response with its own 5XX page.
return Response(payload, status=200, mimetype="application/json") return Response(payload, status=200, mimetype="application/json")
# The function extracts the option identifiers from the query string and normalises comma-separated values into a list. # The function extracts the option identifiers from the query string and normalises comma-separated values into a list.
...@@ -291,12 +291,12 @@ def eeccx_pdf(tarif_id: str): ...@@ -291,12 +291,12 @@ def eeccx_pdf(tarif_id: str):
# The OAuth token is obtained and an error response is returned when token retrieval fails. # The OAuth token is obtained and an error response is returned when token retrieval fails.
token, err = _get_token() token, err = _get_token()
if err: if err:
return _json_error(err, 502) return _json_error(err)
# The partner API is called and an error response is returned when the API invocation fails. # The partner API is called and an error response is returned when the API invocation fails.
api_json, err = _partner_api(token, tarif_id, options) api_json, err = _partner_api(token, tarif_id, options)
if err: if err:
return _json_error(err, 502) return _json_error(err)
# The pdf_url variable tries to extract the PCS or PCI PDF link from the partner API response JSON. # The pdf_url variable tries to extract the PCS or PCI PDF link from the partner API response JSON.
pdf_url = api_json.get("pcsPdf") or api_json.get("pciPdf") pdf_url = api_json.get("pcsPdf") or api_json.get("pciPdf")
...@@ -304,12 +304,12 @@ def eeccx_pdf(tarif_id: str): ...@@ -304,12 +304,12 @@ def eeccx_pdf(tarif_id: str):
# The following conditional branch returns an error response when no PDF URL is present in the API response. # The following conditional branch returns an error response when no PDF URL is present in the API response.
if not pdf_url: if not pdf_url:
msg = api_json.get("message") or "Keine PDF-URL in der API-Antwort." msg = api_json.get("message") or "Keine PDF-URL in der API-Antwort."
return _json_error(msg, 502) return _json_error(msg)
# The PDF is downloaded and an error response is returned when the download fails. # The PDF is downloaded and an error response is returned when the download fails.
pdf_bytes, err = _download_pdf(pdf_url) pdf_bytes, err = _download_pdf(pdf_url)
if err: if err:
return _json_error(err, 502) return _json_error(err)
# A unique hash is generated so the temporary file and the S3 object name are collision-free. # A unique hash is generated so the temporary file and the S3 object name are collision-free.
hash_name = _hash_id_options(tarif_id, options) hash_name = _hash_id_options(tarif_id, options)
...@@ -326,7 +326,7 @@ def eeccx_pdf(tarif_id: str): ...@@ -326,7 +326,7 @@ def eeccx_pdf(tarif_id: str):
# The following conditional branch returns an error response when the S3 upload fails. # The following conditional branch returns an error response when the S3 upload fails.
if not url: if not url:
return _json_error(f"Upload zu S3 fehlgeschlagen für key={s3_key}", 502) return _json_error(f"Upload zu S3 fehlgeschlagen für key={s3_key}")
# A JSON response is returned containing the public URL of the uploaded PDF. # A JSON response is returned containing the public URL of the uploaded PDF.
payload = json.dumps({"url": url}, ensure_ascii=False) payload = json.dumps({"url": url}, ensure_ascii=False)
......
Markdown is supported
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