Skip to content

Commit e89d27f

Browse files
authored
Fix: return 422 on POST /messages if body is not JSON (#475)
Problem: Posting to /messages without a body causes a 500. Solution: catch the error and raise a 422 instead.
1 parent 1230660 commit e89d27f

File tree

1 file changed

+3
-0
lines changed
  • src/aleph/web/controllers

1 file changed

+3
-0
lines changed

src/aleph/web/controllers/p2p.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ async def pub_message(request: web.Request):
190190
request_data = PubMessageRequest.parse_obj(await request.json())
191191
except ValidationError as e:
192192
raise web.HTTPUnprocessableEntity(body=e.json(indent=4))
193+
except ValueError:
194+
# Body must be valid JSON
195+
raise web.HTTPUnprocessableEntity()
193196

194197
pending_message = _validate_message_dict(request_data.message_dict)
195198

0 commit comments

Comments
 (0)