Open
Description
- Checking for empty data before attempting decoding, which can prevent unnecessary errors.
- More explicit handling of the case when the data is empty.
For example:
local function request_json(req)
local data = req:read_cached()
if data == '' then
return {}
end
local s, json = pcall(json.decode, data)
if not s then
error(sprintf("Can't decode json in request '%s': %s",
data, tostring(json)))
return nil
end
return json
end
This logic introduces optimization by avoiding unnecessary pcall
invocation. It also allows handling a 500 error. However, of course, this requires attention from the developers of tarantool/http
. I do not guarantee that the above code will not break some logic.
Metadata
Metadata
Assignees
Labels
No labels