/** * exception_handler * * Function to handle exceptions from the API * * @param string $error_message The error message of the exception * @param string $error_type The exception class * @param Exception $exception The actual exception object itself * @access public * @return void */ public function exception_handler($error_message, $error_type, $exception) { // Let's do different things, based on the type of the error if ($exception instanceof ActiveRecordValidationException) { // Grab our validation errors from our exception $error_data = $exception->get_errors(true); $verbose_exception = new InvalidApiParameters($exception->getMessage(), null, $exception); $verbose_exception->set_more_info($error_data); // Handle the rest with our parent. :) parent::exception_handler($verbose_exception->getMessage(), get_class($verbose_exception), $verbose_exception); } elseif ($exception instanceof RedisConnectionException) { // Let's handle the exception gracefully $this->app->abort(502, 'REDIS_EXCEPTION', $exception->getMessage()); } elseif ($exception instanceof HTTPBasicUnauthorized) { // Grab our "realm" $realm = $this->config['app-meta']['app_url']; // Tell the device/consumer that they must pass auth data $this->response->header('WWW-Authenticate', 'Basic realm="' . $realm . '"'); // Handle the rest with our parent. :) parent::exception_handler($error_message, $error_type, $exception); } else { parent::exception_handler($error_message, $error_type, $exception); } }