Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/func_python/cloudevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ async def __call__(self, scope, receive, send):
while True:
message = await receive()
if message['type'] == 'lifespan.startup':
await self.on_start()
try:
await self.on_start()
except Exception as e:
logging.error("function startup failed: %s", e)
await send({'type': 'lifespan.startup.failed',
'message': str(e)})
return
await send({'type': 'lifespan.startup.complete'})
elif message['type'] == 'lifespan.shutdown':
await self.on_stop()
Expand Down Expand Up @@ -253,7 +259,7 @@ async def send_exception(send, code, message):
'headers': [[b'content-type', b'text/plain']],
})
await send({
'type': 'http.response.body', 'body': message,
'type': 'http.response.body', 'body': message.encode('utf-8') if isinstance(message, str) else message,
})


Expand Down
10 changes: 8 additions & 2 deletions src/func_python/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ async def __call__(self, scope, receive, send):
while True:
message = await receive()
if message['type'] == 'lifespan.startup':
await self.on_start()
try:
await self.on_start()
except Exception as e:
logging.error("function startup failed: %s", e)
await send({'type': 'lifespan.startup.failed',
'message': str(e)})
return
await send({'type': 'lifespan.startup.complete'})
elif message['type'] == 'lifespan.shutdown':
await self.on_stop()
Expand Down Expand Up @@ -186,5 +192,5 @@ async def send_exception(send, code, message):
'headers': [[b'content-type', b'text/plain']],
})
await send({
'type': 'http.response.body', 'body': message,
'type': 'http.response.body', 'body': message.encode('utf-8') if isinstance(message, str) else message,
})
Loading