Skip to content
Merged
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
16 changes: 11 additions & 5 deletions lib/public/AppFramework/Http/JSONResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ public function __construct($data=array(), $statusCode=Http::STATUS_OK) {

/**
* Returns the rendered json
* @return string the rendered json
* @return string|null the rendered json
* @since 6.0.0
* @throws \Exception If data could not get encoded
*/
public function render() {
$response = json_encode($this->data, JSON_HEX_TAG);
if($response === false) {
throw new \Exception(sprintf('Could not json_encode due to invalid ' .
'non UTF-8 characters in the array: %s', var_export($this->data, true)));
if ($this->getStatus() === Http::STATUS_NO_CONTENT
|| $this->getStatus() === Http::STATUS_NOT_MODIFIED
) {
$response = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also log that the content was truncated. Otherwise this is weird behavior to get the body just deleted. Debug should be enough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to add a dependency on the logger. The Response class is too important and should still function if the logging breaks so the user gets a response ... I have seen that kind of problem too often.

} else {
$response = json_encode($this->data, JSON_HEX_TAG);
if ($response === false) {
throw new \Exception(sprintf('Could not json_encode due to invalid ' .
'non UTF-8 characters in the array: %s', var_export($this->data, true)));
}
}

return $response;
Expand Down