<commit_before><?php
namespace App\Error;

use Cake\Core\Configure;
use Cake\Error\Debugger;
use Cake\Network\Exception\HttpException;
use Cake\Network\Exception\InternalErrorException;
use Crud\Error\ExceptionRenderer;

class ApiExceptionRenderer extends ExceptionRenderer
{

	protected function _outputMessage($template)
	{
		$error = $this->controller->viewVars['error'];
		if(!($error instanceof HttpException))
			$error = new InternalErrorException($error->getMessage());

		$data = [];
		$data['class'] = 'Error';
		$data['code'] = $error->getCode() ?: 500;
		$data['url'] = '/'. $this->controller->request->url;
		$data['message'] = $error->getMessage();
		$data['errors'] = @$this->controller->viewVars['errors'];

		$jsonOptions = JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT;
		if(Configure::read('debug'))
			$jsonOptions = $jsonOptions | JSON_PRETTY_PRINT;

		$this->controller->response->type('json');
		$this->controller->response->body(json_encode($data, $jsonOptions));
		$this->controller->response->statusCode($data['code']);
		return $this->controller->response;
	}

}<commit_msg>ApiExceptionRenderer: clean up<commit_after><?php
namespace App\Error;

use Cake\Core\Configure;
use Cake\Error\Debugger;
use Cake\Network\Exception\HttpException;
use Cake\Network\Exception\InternalErrorException;
use Crud\Error\ExceptionRenderer;
use Exception;

class ApiExceptionRenderer extends ExceptionRenderer
{

	protected function _outputMessage($template)
	{
		$error = $this->controller->viewVars['error'];
		$status = $code = $error->getCode();
		try {
			$this->controller->response->statusCode($status);
		} catch(Exception $e) {
			$status = 500;
			$this->controller->response->statusCode($status);
		}

		$errors = [];
		if(isset($this->controller->viewVars['errors'])) {
			$errors = $this->controller->viewVars['errors'];
		}

		$data = [];
		$data['class'] = 'Error';
		$data['code'] = $code;
		$data['url'] = $this->controller->request->here();
		$data['message'] = $error->getMessage();
		$data['errors'] = $errors;

		$jsonOptions = JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_AMP|JSON_HEX_QUOT;
		if(Configure::read('debug'))
			$jsonOptions = $jsonOptions | JSON_PRETTY_PRINT;

		$this->controller->response->type('json');
		$this->controller->response->body(json_encode($data, $jsonOptions));
		return $this->controller->response;
	}
}
{'fraction_non_alphanumeric': 0.18197206940330088, 'fraction_numerical': 0.0025391451544646637, 'mean_word_length': 5.9734513274336285, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 49, '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': '3291989', 'n_tokens_mistral': 820, 'n_tokens_neox': 762, 'n_words': 114}