From 31720b59fde1a26a7135befe2fa7da7661dd3434 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 17 Feb 2016 09:12:34 +1100 Subject: [PATCH] Improving error reporting API --- app/Http/Controllers/InvoiceApiController.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index 6bac870557b0..17259da12a43 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -284,15 +284,21 @@ class InvoiceApiController extends BaseAPIController $error = null; Log::info($data); - + $invoice = Invoice::scope($data['id'])->withTrashed()->first(); if(!$invoice) return $this->errorResponse(['message'=>'Invoice does not exist.'], 400); - $emailAction = $this->mailer->sendInvoice($invoice); + try { + $this->mailer->sendInvoice($invoice); + } + catch(\Exception $e) + { + $this->errorResponse(['message'=>'There was an error sending the invoice'], 400); + } - if(($error) || ($emailAction === FALSE)) { + if($error) { return $this->errorResponse(['message'=>'There was an error sending the invoice'], 400); } else {