Skip to content

Commit

Permalink
尝试修复记录日志时出现的 'str' object has no attribute 'status'问题
Browse files Browse the repository at this point in the history
  • Loading branch information
helloplhm-qwq committed Dec 24, 2023
1 parent 514c8df commit 635ae72
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ async def handle_request(request):
return handleResult({'code': 6, 'msg': '未找到您所请求的资源', 'data': None}, 404)

resp = await handler(request)
if (isinstance(resp, str)):
resp = Response(body = resp, content_type='text/plain', status = 200)
elif (isinstance(resp, dict):
resp = handleResult(resp)
elif (not isinstance(resp, Response)):
resp = Response(body = str(resp), content_type='text/plain', status = 200)
aiologger.info(f'{request.remote_addr} - {request.method} "{request.path}", {resp.status}')
return resp
except:
Expand Down

0 comments on commit 635ae72

Please sign in to comment.