From 4a033ce925d58f7d1d1ce2599959fe6a39de14c3 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 17 Feb 2016 08:57:06 +1100 Subject: [PATCH] Improving error reporting API --- app/Http/Controllers/InvoiceApiController.php | 11 +++++++---- app/Ninja/Mailers/ContactMailer.php | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/InvoiceApiController.php b/app/Http/Controllers/InvoiceApiController.php index f6a5b9b60b3d..f22be4b78770 100644 --- a/app/Http/Controllers/InvoiceApiController.php +++ b/app/Http/Controllers/InvoiceApiController.php @@ -282,12 +282,15 @@ class InvoiceApiController extends BaseAPIController $data = Input::all(); $error = null; - $invoice = Invoice::scope($data['id'])->firstOrFail(); + $invoice = Invoice::scope($data['id'])->withTrashed()->first(); - $this->mailer->sendInvoice($invoice); + if(!$invoice) + return $this->errorResponse(['message'=>'Invoice does not exist.'], 400); - if($error) { - $response['error'] = "There was an error sending the invoice"; + $emailAction = $this->mailer->sendInvoice($invoice); + + if(($error) || ($emailAction === FALSE)) { + return $this->errorResponse(['message'=>'There was an error sending the invoice'], 400); } else { $response = json_encode(RESULT_SUCCESS, JSON_PRETTY_PRINT); diff --git a/app/Ninja/Mailers/ContactMailer.php b/app/Ninja/Mailers/ContactMailer.php index 8959602ce6a2..a5861ab94a3a 100644 --- a/app/Ninja/Mailers/ContactMailer.php +++ b/app/Ninja/Mailers/ContactMailer.php @@ -41,6 +41,8 @@ class ContactMailer extends Mailer $client = $invoice->client; $account = $invoice->account; + $response = false; + if ($client->trashed()) { return trans('texts.email_errors.inactive_client'); } elseif ($invoice->trashed()) {