Replace the default exception classes with more specific ones

This commit is contained in:
Alex Tselegidis 2022-06-20 12:31:11 +03:00
parent a9e2e6583d
commit 658ac78d8f
16 changed files with 37 additions and 37 deletions

View file

@ -86,7 +86,7 @@ class Account extends EA_Controller {
{ {
if (cannot('edit', PRIV_USER_SETTINGS)) if (cannot('edit', PRIV_USER_SETTINGS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$account = request('account'); $account = request('account');

View file

@ -447,7 +447,7 @@ class Booking extends EA_Controller {
if ( ! $appointment['id_users_provider']) if ( ! $appointment['id_users_provider'])
{ {
throw new Exception(lang('requested_hour_is_unavailable')); throw new RuntimeException(lang('requested_hour_is_unavailable'));
} }
$provider = $this->providers_model->find($appointment['id_users_provider']); $provider = $this->providers_model->find($appointment['id_users_provider']);

View file

@ -87,7 +87,7 @@ class Booking_settings extends EA_Controller {
{ {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$settings = request('booking_settings', []); $settings = request('booking_settings', []);

View file

@ -89,7 +89,7 @@ class Business_settings extends EA_Controller {
{ {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$settings = request('business_settings', []); $settings = request('business_settings', []);
@ -129,7 +129,7 @@ class Business_settings extends EA_Controller {
{ {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$working_plan = request('working_plan'); $working_plan = request('working_plan');

View file

@ -190,7 +190,7 @@ class Calendar extends EA_Controller {
if ( ! $required_permissions) if ( ! $required_permissions)
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$this->customers_model->only($customer, [ $this->customers_model->only($customer, [
@ -225,7 +225,7 @@ class Calendar extends EA_Controller {
if ($required_permissions == FALSE) if ($required_permissions == FALSE)
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
// If the appointment does not contain the customer record id, then it means that is going to be // If the appointment does not contain the customer record id, then it means that is going to be
@ -298,14 +298,14 @@ class Calendar extends EA_Controller {
{ {
if (cannot('delete', 'appointments')) if (cannot('delete', 'appointments'))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$appointment_id = request('appointment_id'); $appointment_id = request('appointment_id');
if (empty($appointment_id)) if (empty($appointment_id))
{ {
throw new Exception('No appointment id provided.'); throw new InvalidArgumentException('No appointment id provided.');
} }
// Store appointment data for later use in this method. // Store appointment data for later use in this method.
@ -357,7 +357,7 @@ class Calendar extends EA_Controller {
if ( ! $required_permissions) if ( ! $required_permissions)
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$provider = $this->providers_model->find($unavailability['id_users_provider']); $provider = $this->providers_model->find($unavailability['id_users_provider']);
@ -390,7 +390,7 @@ class Calendar extends EA_Controller {
{ {
if (cannot('delete', PRIV_APPOINTMENTS)) if (cannot('delete', PRIV_APPOINTMENTS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$unavailability_id = request('unavailability_id'); $unavailability_id = request('unavailability_id');
@ -424,7 +424,7 @@ class Calendar extends EA_Controller {
{ {
if (cannot('edit', PRIV_USERS)) if (cannot('edit', PRIV_USERS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$date = request('date'); $date = request('date');
@ -456,7 +456,7 @@ class Calendar extends EA_Controller {
if ( ! $required_permissions) if ( ! $required_permissions)
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$date = request('date'); $date = request('date');
@ -574,7 +574,7 @@ class Calendar extends EA_Controller {
{ {
if (cannot('view', PRIV_APPOINTMENTS)) if (cannot('view', PRIV_APPOINTMENTS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$record_id = request('record_id'); $record_id = request('record_id');

View file

@ -85,7 +85,7 @@ class General_settings extends EA_Controller {
{ {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$settings = request('general_settings', []); $settings = request('general_settings', []);

View file

@ -386,7 +386,7 @@ class Google extends EA_Controller {
if (cannot('edit', PRIV_USERS) && (int)$user_id !== (int)$provider_id) if (cannot('edit', PRIV_USERS) && (int)$user_id !== (int)$provider_id)
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$calendar_id = request('calendar_id'); $calendar_id = request('calendar_id');
@ -427,7 +427,7 @@ class Google extends EA_Controller {
cannot('edit', PRIV_USERS) cannot('edit', PRIV_USERS)
&& (int)$user_id !== (int)$provider_id) && (int)$user_id !== (int)$provider_id)
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$this->providers_model->set_setting($provider_id, 'google_sync', FALSE); $this->providers_model->set_setting($provider_id, 'google_sync', FALSE);

View file

@ -78,7 +78,7 @@ class Legal_settings extends EA_Controller {
{ {
if (cannot('edit', PRIV_SYSTEM_SETTINGS)) if (cannot('edit', PRIV_SYSTEM_SETTINGS))
{ {
throw new Exception('You do not have the required permissions for this task.'); throw new RuntimeException('You do not have the required permissions for this task.');
} }
$settings = request('legal_settings', []); $settings = request('legal_settings', []);

View file

@ -35,7 +35,7 @@ class Localization extends EA_Controller {
if ( ! in_array($language, config('available_languages'))) if ( ! in_array($language, config('available_languages')))
{ {
throw new Exception('Translations for the given language does not exist (' . request('language') . ').'); throw new RuntimeException('Translations for the given language does not exist (' . request('language') . ').');
} }
$language = request('language'); $language = request('language');

View file

@ -139,12 +139,12 @@ class Providers_api_v1 extends EA_Controller {
if ( ! array_key_exists('services', $provider)) if ( ! array_key_exists('services', $provider))
{ {
throw new Exception('No services property provided.'); throw new InvalidArgumentException('No services property provided.');
} }
if ( ! array_key_exists('settings', $provider)) if ( ! array_key_exists('settings', $provider))
{ {
throw new Exception('No settings property provided.'); throw new InvalidArgumentException('No settings property provided.');
} }
if ( ! array_key_exists('working_plan', $provider['settings'])) if ( ! array_key_exists('working_plan', $provider['settings']))

View file

@ -49,7 +49,7 @@ class Secretaries_api_v1 extends EA_Controller {
$order_by = $this->api->request_order_by(); $order_by = $this->api->request_order_by();
$fields = $this->api->request_fields(); $fields = $this->api->request_fields();
$with = $this->api->request_with(); $with = $this->api->request_with();
$secretaries = empty($keyword) $secretaries = empty($keyword)
@ -132,12 +132,12 @@ class Secretaries_api_v1 extends EA_Controller {
if ( ! array_key_exists('providers', $secretary)) if ( ! array_key_exists('providers', $secretary))
{ {
throw new Exception('No providers property provided.'); throw new InvalidArgumentException('No providers property provided.');
} }
if ( ! array_key_exists('settings', $secretary)) if ( ! array_key_exists('settings', $secretary))
{ {
throw new Exception('No settings property provided.'); throw new InvalidArgumentException('No settings property provided.');
} }
$secretary_id = $this->secretaries_model->save($secretary); $secretary_id = $this->secretaries_model->save($secretary);

View file

@ -29,7 +29,7 @@ function hash_password(string $salt, string $password): string
{ {
if (strlen($password) > MAX_PASSWORD_LENGTH) if (strlen($password) > MAX_PASSWORD_LENGTH)
{ {
throw new Exception('The provided password is too long, please use a shorter value.'); throw new InvalidArgumentException('The provided password is too long, please use a shorter value.');
} }
$half = (int)(strlen($salt) / 2); $half = (int)(strlen($salt) / 2);

View file

@ -190,7 +190,7 @@ class Email_messages {
$date_format = 'Y/m/d'; $date_format = 'Y/m/d';
break; break;
default: default:
throw new Exception('Invalid date_format value: ' . $settings['date_format']); throw new InvalidArgumentException('Invalid date_format value: ' . $settings['date_format']);
} }
switch ($settings['time_format']) switch ($settings['time_format'])
@ -202,7 +202,7 @@ class Email_messages {
$time_format = 'g:i a'; $time_format = 'g:i a';
break; break;
default: default:
throw new Exception('Invalid time_format value: ' . $settings['time_format']); throw new InvalidArgumentException('Invalid time_format value: ' . $settings['time_format']);
} }
$appointment_timezone = new DateTimeZone($provider['timezone']); $appointment_timezone = new DateTimeZone($provider['timezone']);

View file

@ -110,7 +110,7 @@ class Google_sync {
if (isset($response['error'])) if (isset($response['error']))
{ {
throw new Exception('Google Authentication Error (' . $response['error'] . '): ' . $response['error_description']); throw new RuntimeException('Google Authentication Error (' . $response['error'] . '): ' . $response['error_description']);
} }
return $response; return $response;

View file

@ -161,12 +161,12 @@ class Instance {
if ( ! file_exists($path)) if ( ! file_exists($path))
{ {
throw new Exception('The backup path does not exist: ' . $path); throw new InvalidArgumentException('The backup path does not exist: ' . $path);
} }
if ( ! is_writable($path)) if ( ! is_writable($path))
{ {
throw new Exception('The backup path is not writable: ' . $path); throw new RuntimeException('The backup path is not writable: ' . $path);
} }
$contents = $this->CI->dbutil->backup(); $contents = $this->CI->dbutil->backup();

View file

@ -123,7 +123,7 @@ class Services_model extends EA_Model {
if ($service['availabilities_type'] !== NULL && $service['availabilities_type'] !== AVAILABILITIES_TYPE_FLEXIBLE if ($service['availabilities_type'] !== NULL && $service['availabilities_type'] !== AVAILABILITIES_TYPE_FLEXIBLE
&& $service['availabilities_type'] !== AVAILABILITIES_TYPE_FIXED) && $service['availabilities_type'] !== AVAILABILITIES_TYPE_FIXED)
{ {
throw new Exception('Service availabilities type must be either ' . AVAILABILITIES_TYPE_FLEXIBLE throw new InvalidArgumentException('Service availabilities type must be either ' . AVAILABILITIES_TYPE_FLEXIBLE
. ' or ' . AVAILABILITIES_TYPE_FIXED . ' (given ' . $service['availabilities_type'] . ')'); . ' or ' . AVAILABILITIES_TYPE_FIXED . ' (given ' . $service['availabilities_type'] . ')');
} }
@ -156,7 +156,7 @@ class Services_model extends EA_Model {
{ {
$service['create_datetime'] = date('Y-m-d H:i:s'); $service['create_datetime'] = date('Y-m-d H:i:s');
$service['update_datetime'] = date('Y-m-d H:i:s'); $service['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->insert('services', $service)) if ( ! $this->db->insert('services', $service))
{ {
throw new RuntimeException('Could not insert service.'); throw new RuntimeException('Could not insert service.');
@ -177,7 +177,7 @@ class Services_model extends EA_Model {
protected function update(array $service): int protected function update(array $service): int
{ {
$service['update_datetime'] = date('Y-m-d H:i:s'); $service['update_datetime'] = date('Y-m-d H:i:s');
if ( ! $this->db->update('services', $service, ['id' => $service['id']])) if ( ! $this->db->update('services', $service, ['id' => $service['id']]))
{ {
throw new RuntimeException('Could not update service.'); throw new RuntimeException('Could not update service.');
@ -222,7 +222,7 @@ class Services_model extends EA_Model {
{ {
$this->db->where('delete_datetime IS NULL'); $this->db->where('delete_datetime IS NULL');
} }
$service = $this->db->get_where('services', ['id' => $service_id])->row_array(); $service = $this->db->get_where('services', ['id' => $service_id])->row_array();
if ( ! $service) if ( ! $service)
@ -286,7 +286,7 @@ class Services_model extends EA_Model {
* @param int|null $offset Record offset. * @param int|null $offset Record offset.
* @param string|null $order_by Order by. * @param string|null $order_by Order by.
* @param bool $with_trashed * @param bool $with_trashed
* *
* @return array Returns an array of services. * @return array Returns an array of services.
*/ */
public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array public function get($where = NULL, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
@ -368,7 +368,7 @@ class Services_model extends EA_Model {
* @param int|null $offset Record offset. * @param int|null $offset Record offset.
* @param string|null $order_by Order by. * @param string|null $order_by Order by.
* @param bool $with_trashed * @param bool $with_trashed
* *
* @return array Returns an array of services. * @return array Returns an array of services.
*/ */
public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array public function search(string $keyword, int $limit = NULL, int $offset = NULL, string $order_by = NULL, bool $with_trashed = FALSE): array
@ -377,7 +377,7 @@ class Services_model extends EA_Model {
{ {
$this->db->where('delete_datetime IS NULL'); $this->db->where('delete_datetime IS NULL');
} }
$services = $this $services = $this
->db ->db
->select() ->select()