Skip to content

Commit 109f7d2

Browse files
committed
Only parse a JSON body if there is one
1 parent 88addd0 commit 109f7d2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

app.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def parse_body
9999
data = nil
100100

101101
begin
102-
data = JSON.parse(request.body.read)
102+
body = request.body.read
103+
104+
data = body.empty? ? {} : JSON.parse(body)
103105
rescue JSON::ParserError
104106
halt 400, json(error: "Sorry, your JSON request could not be parsed")
105107
end

0 commit comments

Comments
 (0)