<commit_before><?php

namespace Neutrino\Error\Writer;

use Neutrino\Constants\Services;
use Neutrino\Error\Error;
use Phalcon\Di;
use Phalcon\Http\Response;

/**
 * Class Json
 *
 * @package     Neutrino\Error\Writer
 */
class Json implements Writable
{

    /**
     * @inheritdoc
     */
    public function handle(Error $error)
    {
        if (!$error->isFateful()) {
            return;
        }

        $di = Di::getDefault();

        if ($di
            && $di->has(Services::RESPONSE)
            && ($response = $di->getShared(Services::RESPONSE)) instanceof Response
            && !$response->isSent()
        ) {
            /** @var \Phalcon\Http\Response $response */
            $response
                ->setStatusCode(500)
                ->setJsonContent($error)
                ->send();
        } else {
            echo json_encode($error);
        }
    }
}<commit_msg>feat(Error\Writer\Json): Don't verbose when not debug<commit_after><?php

namespace Neutrino\Error\Writer;

use Neutrino\Constants\Services;
use Neutrino\Error\Error;
use Phalcon\Di;
use Phalcon\Http\Response;

/**
 * Class Json
 *
 * @package     Neutrino\Error\Writer
 */
class Json implements Writable
{

    /**
     * @inheritdoc
     */
    public function handle(Error $error)
    {
        if (!$error->isFateful()) {
            return;
        }

        $di = Di::getDefault();

        if ($di
            && $di->has(Services::RESPONSE)
            && ($response = $di->getShared(Services::RESPONSE)) instanceof Response
            && !$response->isSent()
        ) {
            /** @var \Phalcon\Http\Response $response */
            $response
                ->setStatusCode(500, 'Internal Server Error')
                ->setJsonContent(APP_DEBUG ? $error : '')
                ->send();
        } else {
            echo json_encode(APP_DEBUG ? $error : '');
        }
    }
}
{'fraction_non_alphanumeric': 0.14421553090332806, 'fraction_numerical': 0.003169572107765452, 'mean_word_length': 1.8142644873699851, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5305742', 'n_tokens_mistral': 580, 'n_tokens_neox': 564, 'n_words': 104}