Improving error reporting API

This commit is contained in:
David Bomba 2016-02-17 08:57:06 +11:00
parent 1ab4bb636f
commit 4a033ce925
2 changed files with 9 additions and 4 deletions

View File

@ -282,12 +282,15 @@ class InvoiceApiController extends BaseAPIController
$data = Input::all(); $data = Input::all();
$error = null; $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) { $emailAction = $this->mailer->sendInvoice($invoice);
$response['error'] = "There was an error sending the invoice";
if(($error) || ($emailAction === FALSE)) {
return $this->errorResponse(['message'=>'There was an error sending the invoice'], 400);
} }
else { else {
$response = json_encode(RESULT_SUCCESS, JSON_PRETTY_PRINT); $response = json_encode(RESULT_SUCCESS, JSON_PRETTY_PRINT);

View File

@ -41,6 +41,8 @@ class ContactMailer extends Mailer
$client = $invoice->client; $client = $invoice->client;
$account = $invoice->account; $account = $invoice->account;
$response = false;
if ($client->trashed()) { if ($client->trashed()) {
return trans('texts.email_errors.inactive_client'); return trans('texts.email_errors.inactive_client');
} elseif ($invoice->trashed()) { } elseif ($invoice->trashed()) {