<commit_before><?php

App::uses('CakeResponse', 'Network');
App::uses('ApiError', 'Error');

class ApiExceptionRenderer {

	public $response = null;
	public $exception = null;

	public function __construct(Exception $exception) {
		$this->response = new CakeResponse();
		try {
			$this->response->statusCode($exception->getCode());
		} catch (CakeException $e) {
			$this->response->statusCode(500);
		}
		$this->exception = $exception;
	}

	public function render() {
		$params = [];
		$errorCode = ApiError::UNKNOWN;

		if ($this->exception instanceof LackParametersException) {
			$errorCode = ApiError::LACK_PARAMETERS;
			$params['lackParameters'] = explode(', ', $this->exception->getMessage());
		} elseif ($this->exception instanceof UnauthenticatedException) {
			$errorCode = ApiError::UNAUTHENTICATED;
		} elseif ($this->exception instanceof UnauthorizedException) {
			$errorCode = ApiError::NOT_AUTHENTICATED;
		}

		$statusCode = $this->response->statusCode();
		$errorMessages = ApiError::messages();
		if (isset($errorMessages[$statusCode])) {
			$errorCode = $statusCode;
		}

		if (Configure::read('debug') > 1 && $errorCode == ApiError::UNKNOWN) {
			$params['debug'] = [
				'message' => $this->exception->getMessage(),
				'trace' => explode("\n", $this->exception->getTraceAsString()),
			];
		}

		$params = [
			'success' => false,
			'code' => $statusCode,
			'errorCode' => $errorCode,
			'errorMessage' => ApiError::message($errorCode),
		] + $params;

		$this->response->body(json_encode($params));
		$this->response->type('json');
		$this->response->send();
	}

}
<commit_msg>Fix importing libs in  ApiExceptionRenderer<commit_after><?php

App::uses('CakeResponse', 'Network');
App::uses('ApiError', 'Api.Error');

class ApiExceptionRenderer {

	public $response = null;
	public $exception = null;

	public function __construct(Exception $exception) {
		$this->response = new CakeResponse();
		try {
			$this->response->statusCode($exception->getCode());
		} catch (CakeException $e) {
			$this->response->statusCode(500);
		}
		$this->exception = $exception;
	}

	public function render() {
		$params = [];
		$errorCode = ApiError::UNKNOWN;

		if ($this->exception instanceof LackParametersException) {
			$errorCode = ApiError::LACK_PARAMETERS;
			$params['lackParameters'] = explode(', ', $this->exception->getMessage());
		} elseif ($this->exception instanceof UnauthenticatedException) {
			$errorCode = ApiError::UNAUTHENTICATED;
		} elseif ($this->exception instanceof UnauthorizedException) {
			$errorCode = ApiError::NOT_AUTHENTICATED;
		}

		$statusCode = $this->response->statusCode();
		$errorMessages = ApiError::messages();
		if (isset($errorMessages[$statusCode])) {
			$errorCode = $statusCode;
		}

		if (Configure::read('debug') > 1 && $errorCode == ApiError::UNKNOWN) {
			$params['debug'] = [
				'message' => $this->exception->getMessage(),
				'trace' => explode("\n", $this->exception->getTraceAsString()),
			];
		}

		$params = [
			'success' => false,
			'code' => $statusCode,
			'errorCode' => $errorCode,
			'errorMessage' => ApiError::message($errorCode),
		] + $params;

		$this->response->body(json_encode($params));
		$this->response->type('json');
		$this->response->send();
	}

}

{'fraction_non_alphanumeric': 0.185150955021565, 'fraction_numerical': 0.0024645717806531116, 'mean_word_length': 4.9143897996357016, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, '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': '344987', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1038, 'n_words': 178}