From 328417c8cf8cfeea4e8a5931de1888ea54772042 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Mon, 1 Jul 2024 12:57:10 +0800 Subject: [PATCH] Laravel Vapor - sync some missing code meant for PerfexCRM --- .../Exceptions/ConnectionErrorException.php | 20 +++++++ .../ConvertsPerfexCRMLeadToCustomer.php | 8 ++- .../Services/CreatesPerfexCRMCustomer.php | 8 ++- .../CreatesPerfexCRMCustomerContact.php | 8 ++- .../CreatesPerfexCRMCustomerProject.php | 8 ++- .../Services/CreatesPerfexCRMInvoice.php | 8 ++- .../CreatesPerfexCRMInvoicePayment.php | 8 ++- .../Services/CreatesPerfexCRMLead.php | 8 ++- .../Services/CreatesPerfexCRMMilestone.php | 8 ++- .../CreatesPerfexCRMSupportTicket.php | 52 +++++++++++++++++++ .../Services/CreatesPerfexCRMTask.php | 8 ++- .../Services/FetchesPerfexCRMCustomer.php | 8 ++- .../Services/FetchesPerfexCRMInvoice.php | 8 ++- .../Services/FetchesPerfexCRMLead.php | 8 ++- .../Services/FetchesPerfexCRMMilestone.php | 8 ++- .../Services/FetchesPerfexCRMProject.php | 8 ++- .../Services/FetchesPerfexCRMTask.php | 8 ++- .../Services/UpdatesPerfexCRMCustomer.php | 8 ++- .../Services/UpdatesPerfexCRMInvoice.php | 8 ++- .../Services/UpdatesPerfexCRMLead.php | 8 ++- .../Services/UpdatesPerfexCRMProject.php | 8 ++- .../Services/UpdatesPerfexCRMTask.php | 8 ++- 22 files changed, 212 insertions(+), 20 deletions(-) create mode 100644 app/Classes/Exceptions/ConnectionErrorException.php create mode 100644 app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMSupportTicket.php diff --git a/app/Classes/Exceptions/ConnectionErrorException.php b/app/Classes/Exceptions/ConnectionErrorException.php new file mode 100644 index 00000000..52189ac8 --- /dev/null +++ b/app/Classes/Exceptions/ConnectionErrorException.php @@ -0,0 +1,20 @@ +info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), $email, $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomer.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomer.php index b7eabaa7..8261c3a2 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomer.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomer.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class CreatesPerfexCRMCustomer @@ -30,7 +31,12 @@ class CreatesPerfexCRMCustomer Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), $companyName, $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerContact.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerContact.php index 12d3d7e8..7d035c0f 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerContact.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerContact.php @@ -5,6 +5,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class CreatesPerfexCRMCustomerContact @@ -37,7 +38,12 @@ class CreatesPerfexCRMCustomerContact Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerProject.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerProject.php index 1f513f31..0042d32d 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerProject.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMCustomerProject.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class CreatesPerfexCRMCustomerProject @@ -36,7 +37,12 @@ class CreatesPerfexCRMCustomerProject Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoice.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoice.php index df952c4b..14a2bba9 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoice.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoice.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoicePerfexCRMObject; @@ -56,7 +57,12 @@ class CreatesPerfexCRMInvoice Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoicePayment.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoicePayment.php index 64590232..16e33159 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoicePayment.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMInvoicePayment.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\Modules\PerfexCRM\DataTransferObjects\InvoicePaymentPerfexCRMObject; @@ -36,7 +37,12 @@ class CreatesPerfexCRMInvoicePayment Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMLead.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMLead.php index 5ecef6e7..f7505d17 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMLead.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMLead.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateLeadPerfexCRMObject; @@ -43,7 +44,12 @@ class CreatesPerfexCRMLead Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMMilestone.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMMilestone.php index 91afd314..f6caf5fb 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMMilestone.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMMilestone.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class CreatesPerfexCRMMilestone @@ -39,7 +40,12 @@ class CreatesPerfexCRMMilestone Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMSupportTicket.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMSupportTicket.php new file mode 100644 index 00000000..34692701 --- /dev/null +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMSupportTicket.php @@ -0,0 +1,52 @@ + $subject, + 'department' => $department, + 'contactid' => $contactid, + 'userid' => $userid, + ]; + + $response = Http::asForm()->withHeaders([ + 'authtoken' => config('perfexcrm.api_key')]) + ->post(config('perfexcrm.base_url').'/api/tickets',$data); + + if($response->successful()){ + $data = $response->json(); + return (object) $data; + }else{ + Log::channel('perfex_crm')->info($response); + return null; + } + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ + $error = 'Support Ticket creation failed'; + Log::error($error. ": ". $exception->getMessage()); + Log::error('Payload: '.json_encode($data)); + throw new MalformedRequestException($error); + } + } +} diff --git a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php index 45105fa9..fc10718f 100644 --- a/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php +++ b/app/Classes/Modules/PerfexCRM/Services/CreatesPerfexCRMTask.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields; use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject; @@ -59,7 +60,12 @@ class CreatesPerfexCRMTask Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMCustomer.php b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMCustomer.php index 6efebec4..7b822d68 100644 --- a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMCustomer.php +++ b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMCustomer.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class FetchesPerfexCRMCustomer @@ -27,7 +28,12 @@ class FetchesPerfexCRMCustomer Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), $email, $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMInvoice.php b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMInvoice.php index 7946cfec..0a612113 100644 --- a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMInvoice.php +++ b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMInvoice.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class FetchesPerfexCRMInvoice @@ -29,7 +30,12 @@ class FetchesPerfexCRMInvoice Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMLead.php b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMLead.php index a3543b20..3d7faa04 100644 --- a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMLead.php +++ b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMLead.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class FetchesPerfexCRMLead @@ -27,7 +28,12 @@ class FetchesPerfexCRMLead Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), $email, $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMMilestone.php b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMMilestone.php index 9c482fe7..bb248e7c 100644 --- a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMMilestone.php +++ b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMMilestone.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class FetchesPerfexCRMMilestone @@ -33,7 +34,12 @@ class FetchesPerfexCRMMilestone Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMProject.php b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMProject.php index ce9762d8..1acad7cf 100644 --- a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMProject.php +++ b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMProject.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class FetchesPerfexCRMProject @@ -33,7 +34,12 @@ class FetchesPerfexCRMProject Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMTask.php b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMTask.php index 0ab2b0fd..b7e313b9 100644 --- a/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMTask.php +++ b/app/Classes/Modules/PerfexCRM/Services/FetchesPerfexCRMTask.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\General\Helper; @@ -47,7 +48,12 @@ class FetchesPerfexCRMTask Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMCustomer.php b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMCustomer.php index 15963c31..35efc999 100644 --- a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMCustomer.php +++ b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMCustomer.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields; use App\Classes\General\Helper; @@ -41,7 +42,12 @@ class UpdatesPerfexCRMCustomer Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php index 9825dde2..c04037b4 100644 --- a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php +++ b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMInvoice.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class UpdatesPerfexCRMInvoice @@ -63,7 +64,12 @@ class UpdatesPerfexCRMInvoice Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMLead.php b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMLead.php index 69ac7fa8..d512f42e 100644 --- a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMLead.php +++ b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMLead.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields; @@ -44,7 +45,12 @@ class UpdatesPerfexCRMLead Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMProject.php b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMProject.php index 4b65347e..5088952b 100644 --- a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMProject.php +++ b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMProject.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class UpdatesPerfexCRMProject @@ -36,7 +37,12 @@ class UpdatesPerfexCRMProject Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server: ' . $exception->getMessage()); } } diff --git a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMTask.php b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMTask.php index 053fa16d..82992c79 100644 --- a/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMTask.php +++ b/app/Classes/Modules/PerfexCRM/Services/UpdatesPerfexCRMTask.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\PerfexCRM\Services; use Illuminate\Support\Facades\Http; use App\Classes\Exceptions\MalformedRequestException; +use App\Classes\Exceptions\ConnectionErrorException; use Illuminate\Support\Facades\Log; class UpdatesPerfexCRMTask @@ -43,7 +44,12 @@ class UpdatesPerfexCRMTask Log::channel('perfex_crm')->info($response); return null; } - }catch(\Exception $exception){ + } + catch(\Illuminate\Http\Client\ConnectionException $exception){ + $error = 'Failed to connect to CRM'; + throw new ConnectionErrorException($error, $exception->getMessage(), "", $exception->getTraceAsString()); + } + catch(\Exception $exception){ throw new MalformedRequestException('Unable to get correct response from Perfex CRM server' . $exception->getMessage()); } }