getndazn / kopytko-framework

A modern Roku's Brightscript framework based on JS world's solutions
MIT License
19 stars 6 forks source link

Do not cache response if expected JSON data is corrupted #50

Open RadoslawZambrowski opened 1 year ago

RadoslawZambrowski commented 1 year ago

This is a Feature Proposal

Description

HttpResponseCreator._parseUrlEventContent function returns {} when ParseJSON is invalid. It may lead to caching invalid responses. At this point, the app knows that the response body is a non-empty string and JSON format is expected. Thus failed JSON parsing suggests that body is corrupted, and caching it may lead to unexpected behavior.

prototype._parseUrlEventContent = function (urlEvent as Object) as Object
  if (NOT m._isJsonResponse(urlEvent)) then return {}

  content = urlEvent.getString()
  if (content = "") then return {}

  data = ParseJSON(content)
  if (data = Invalid) then return {}

  return data
end function