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))
{
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');

View file

@ -447,7 +447,7 @@ class Booking extends EA_Controller {
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']);

View file

@ -87,7 +87,7 @@ class Booking_settings extends EA_Controller {
{
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', []);

View file

@ -89,7 +89,7 @@ class Business_settings extends EA_Controller {
{
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', []);
@ -129,7 +129,7 @@ class Business_settings extends EA_Controller {
{
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');

View file

@ -190,7 +190,7 @@ class Calendar extends EA_Controller {
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, [
@ -225,7 +225,7 @@ class Calendar extends EA_Controller {
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
@ -298,14 +298,14 @@ class Calendar extends EA_Controller {
{
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');
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.
@ -357,7 +357,7 @@ class Calendar extends EA_Controller {
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']);
@ -390,7 +390,7 @@ class Calendar extends EA_Controller {
{
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');
@ -424,7 +424,7 @@ class Calendar extends EA_Controller {
{
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');
@ -456,7 +456,7 @@ class Calendar extends EA_Controller {
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');
@ -574,7 +574,7 @@ class Calendar extends EA_Controller {
{
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');

View file

@ -85,7 +85,7 @@ class General_settings extends EA_Controller {
{
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', []);

View file

@ -386,7 +386,7 @@ class Google extends EA_Controller {
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');
@ -427,7 +427,7 @@ class Google extends EA_Controller {
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.');
}
$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))
{
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', []);

View file

@ -35,7 +35,7 @@ class Localization extends EA_Controller {
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');

View file

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

View file

@ -132,12 +132,12 @@ class Secretaries_api_v1 extends EA_Controller {
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))
{
throw new Exception('No settings property provided.');
throw new InvalidArgumentException('No settings property provided.');
}
$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)
{
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);

View file

@ -190,7 +190,7 @@ class Email_messages {
$date_format = 'Y/m/d';
break;
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'])
@ -202,7 +202,7 @@ class Email_messages {
$time_format = 'g:i a';
break;
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']);

View file

@ -110,7 +110,7 @@ class Google_sync {
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;

View file

@ -161,12 +161,12 @@ class Instance {
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))
{
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();

View file

@ -123,7 +123,7 @@ class Services_model extends EA_Model {
if ($service['availabilities_type'] !== NULL && $service['availabilities_type'] !== AVAILABILITIES_TYPE_FLEXIBLE
&& $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'] . ')');
}