Api v1.14.0 (#1394)
* fix(chalice): cast note's session_id to string * fix(chalice): cast all session_id to string * fix(chalice): EE cast all session_id to string
This commit is contained in:
parent
4cf50b3066
commit
065c139494
3 changed files with 27 additions and 3 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import logging
|
||||
import math
|
||||
import random
|
||||
import re
|
||||
|
|
@ -9,7 +8,6 @@ from urllib.parse import urlparse
|
|||
from decouple import config
|
||||
|
||||
import schemas
|
||||
from chalicelib.utils import smtp
|
||||
from chalicelib.utils.TimeUTC import TimeUTC
|
||||
|
||||
|
||||
|
|
@ -319,3 +317,19 @@ def obfuscate(text, keep_last: int = 4):
|
|||
if len(text) <= keep_last:
|
||||
return "*" * len(text)
|
||||
return "*" * (len(text) - keep_last) + text[-keep_last:]
|
||||
|
||||
|
||||
def cast_session_id_to_string(data):
|
||||
if not isinstance(data, dict) and not isinstance(data, list):
|
||||
return data
|
||||
if isinstance(data, list):
|
||||
for i, item in enumerate(data):
|
||||
data[i] = cast_session_id_to_string(item)
|
||||
elif isinstance(data, dict):
|
||||
keys = data.keys()
|
||||
if "sessionId" in keys:
|
||||
data["sessionId"] = str(data["sessionId"])
|
||||
else:
|
||||
for key in keys:
|
||||
data[key] = cast_session_id_to_string(data[key])
|
||||
return data
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ from starlette.requests import Request
|
|||
from starlette.responses import Response, JSONResponse
|
||||
|
||||
import schemas
|
||||
from chalicelib.utils import helper
|
||||
|
||||
|
||||
async def OR_context(request: Request) -> schemas.CurrentContext:
|
||||
|
|
@ -33,6 +34,9 @@ class ORRoute(APIRoute):
|
|||
if isinstance(response, JSONResponse):
|
||||
response: JSONResponse = response
|
||||
body = json.loads(response.body.decode('utf8'))
|
||||
body=helper.cast_session_id_to_string(body)
|
||||
response = JSONResponse(content=body, status_code=response.status_code, headers=response.headers,
|
||||
media_type=response.media_type, background=response.background)
|
||||
if response.status_code == 200 \
|
||||
and body is not None and isinstance(body, dict) \
|
||||
and body.get("errors") is not None:
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from starlette.requests import Request
|
|||
from starlette.responses import Response, JSONResponse
|
||||
|
||||
import schemas_ee
|
||||
from chalicelib.utils import helper
|
||||
from chalicelib.core import traces
|
||||
|
||||
|
||||
|
|
@ -37,7 +38,12 @@ class ORRoute(APIRoute):
|
|||
if isinstance(response, JSONResponse):
|
||||
response: JSONResponse = response
|
||||
body = json.loads(response.body.decode('utf8'))
|
||||
if response.status_code == 200 and body is not None and body.get("errors") is not None:
|
||||
body = helper.cast_session_id_to_string(body)
|
||||
response = JSONResponse(content=body, status_code=response.status_code, headers=response.headers,
|
||||
media_type=response.media_type, background=response.background)
|
||||
if response.status_code == 200 \
|
||||
and body is not None and isinstance(body, dict) \
|
||||
and body.get("errors") is not None:
|
||||
if "not found" in body["errors"][0]:
|
||||
response.status_code = status.HTTP_404_NOT_FOUND
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue