Skip to content

Commit

Permalink
Error handling around return statement
Browse files Browse the repository at this point in the history
  • Loading branch information
TechPrototyper committed Apr 9, 2024
1 parent 7365637 commit 041c792
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions API/function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import logging
from datetime import datetime
from azure_openai import InteractWithOpenAI

import aiohttp


# Initialisierung der Funktion App
Expand Down Expand Up @@ -88,9 +88,14 @@ async def chat(req: func.HttpRequest) -> func.HttpResponse:
logging.info(f"Chat-Endpoint came back: Response: {http_status}: {response}")

logging.info("InteractWithOpenAI() Context left, About to Return data to Caller!" )
# Ensure the response is a string encoded in UTF-8
response_body = response.encode('utf-8').decode('utf-8')

return func.HttpResponse(response, status_code=http_status, headers={"Content-Type": "text/plain"})

try:
return func.HttpResponse(response_body, status_code=http_status, headers={"Content-Type": "text/plain; charset=utf-8"})
except Exception as e:
logging.error(f"Error returning the response: {e}")
return func.HttpResponse("Internal server error", status_code=500)

# Ping- und Status-Endpunkte, noch zu implementieren
# Ggf. separate Parameter-Klassen für Ping und Status implementieren
Expand Down

0 comments on commit 041c792

Please sign in to comment.