<commit_before><?php
namespace CkTools\Error;

class ApiExceptionRenderer extends \Cake\Error\ExceptionRenderer
{

    /**
     * overwriting get controller
     *
     * @return Controller instance of controller
     */
    protected function _getController()
    {
        $controller = parent::_getController();
        $controller->loadComponent('RequestHandler');
        $controller->RequestHandler->renderAs($controller, 'json');
        return $controller;
    }
}<commit_msg>make sure a generic exception code is returned as a string<commit_after><?php
namespace CkTools\Error;

class ApiExceptionRenderer extends \Cake\Error\ExceptionRenderer
{

    /**
     * overwriting get controller
     *
     * @return Controller instance of controller
     */
    protected function _getController()
    {
        $controller = parent::_getController();
        $controller->loadComponent('RequestHandler');
        $controller->RequestHandler->renderAs($controller, 'json');
        return $controller;
    }
    
    /**
     * Make sure the code value is returned as a string
     * // FIXME make this configurable via an option
     *
     * @param \Exception $exception Exception
     * @return string Error code value within range 400 to 506
     */
    protected function _code(\Exception $exception)
    {
        return (string)parent::_code($exception);
    }
}
{'fraction_non_alphanumeric': 0.10050983248361253, 'fraction_numerical': 0.004369992716678805, 'mean_word_length': 2.9369627507163325, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '6700219', 'n_tokens_mistral': 344, 'n_tokens_neox': 342, 'n_words': 97}