<commit_before><?php
/**
 * Whoops - php errors for cool kids
 * @author <NAME> <http://github.com/filp>
 */

namespace ByJG\RestServer\Whoops;

use Whoops\Exception\Formatter;
use Whoops\Handler\Handler;
use Whoops\Handler\JsonResponseHandler as OriginalJsonHandler;

/**
 * Catches an exception and converts it to a JSON
 * response. Additionally can also return exception
 * frames for consumption by an API.
 */
class JsonResponseHandler extends OriginalJsonHandler
{

    use WhoopsDebugTrait;
    use WhoopsHeaderTrait;

    /**
     * @return int
     */
    public function handle()
    {
        $response = array(
            'error' => Formatter::formatExceptionAsDataArray(
                $this->getInspector(),
                $this->addTraceToOutput()
            ),
        );

        $debug = $this->getDataTable();
        if (count($debug) > 0) {
            $response["debug"] = $debug;
        }

        echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);

        return Handler::QUIT;
    }

}<commit_msg>Added the Status Code on Error<commit_after><?php
/**
 * Whoops - php errors for cool kids
 * @author <NAME> <http://github.com/filp>
 */

namespace ByJG\RestServer\Whoops;

use Whoops\Exception\Formatter;
use Whoops\Handler\Handler;
use Whoops\Handler\JsonResponseHandler as OriginalJsonHandler;

/**
 * Catches an exception and converts it to a JSON
 * response. Additionally can also return exception
 * frames for consumption by an API.
 */
class JsonResponseHandler extends OriginalJsonHandler
{

    use WhoopsDebugTrait;
    use WhoopsHeaderTrait;

    /**
     * @return int
     */
    public function handle()
    {
        $response = array(
            'error' => Formatter::formatExceptionAsDataArray(
                $this->getInspector(),
                $this->addTraceToOutput()
            ),
        );

        $debug = $this->getDataTable();
        if (count($debug) > 0) {
            $response["debug"] = $debug;
        }

        $this->setProperHeader($this->getException());

        echo json_encode($response, defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);

        return Handler::QUIT;
    }

}
{'fraction_non_alphanumeric': 0.11478338543992854, 'fraction_numerical': 0.001786511835640911, 'mean_word_length': 2.6363636363636362, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '5982403', 'n_tokens_mistral': 662, 'n_tokens_neox': 635, 'n_words': 154}