diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 15284d1b7fa5..111c48340754 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -60,7 +60,7 @@ class Handler extends ExceptionHandler return false; } // Log 404s to a separate file - $errorStr = date('Y-m-d h:i:s') . ' ' . request()->url() . "\n" . json_encode(Utils::prepareErrorData('PHP')) . "\n\n"; + $errorStr = date('Y-m-d h:i:s') . ' ' . $e->getMessage() . ' URL:' . request()->url() . "\n" . json_encode(Utils::prepareErrorData('PHP')) . "\n\n"; @file_put_contents(storage_path('logs/not-found.log'), $errorStr, FILE_APPEND); return false; } elseif ($e instanceof HttpResponseException) { @@ -69,7 +69,7 @@ class Handler extends ExceptionHandler if (! Utils::isTravis()) { Utils::logError(Utils::getErrorString($e)); - $stacktrace = date('Y-m-d h:i:s') . ' ' . $e->getTraceAsString() . "\n\n"; + $stacktrace = date('Y-m-d h:i:s') . ' ' . $e->getMessage() . ': ' . $e->getTraceAsString() . "\n\n"; @file_put_contents(storage_path('logs/stacktrace.log'), $stacktrace, FILE_APPEND); return false; } else { diff --git a/app/Http/Controllers/OnlinePaymentController.php b/app/Http/Controllers/OnlinePaymentController.php index 696a4c6736dd..a2e3f76d767d 100644 --- a/app/Http/Controllers/OnlinePaymentController.php +++ b/app/Http/Controllers/OnlinePaymentController.php @@ -149,6 +149,10 @@ class OnlinePaymentController extends BaseController */ public function offsitePayment($invitationKey = false, $gatewayTypeAlias = false) { + if (Crawler::isCrawler()) { + return redirect()->to(NINJA_WEB_URL, 301); + } + $invitationKey = $invitationKey ?: Session::get('invitation_key'); $invitation = Invitation::with('invoice.invoice_items', 'invoice.client.currency', 'invoice.client.account.account_gateways.gateway') ->where('invitation_key', '=', $invitationKey)->firstOrFail(); diff --git a/app/Http/Requests/EntityRequest.php b/app/Http/Requests/EntityRequest.php index e7cf003c091a..e47920452bd7 100644 --- a/app/Http/Requests/EntityRequest.php +++ b/app/Http/Requests/EntityRequest.php @@ -18,6 +18,8 @@ class EntityRequest extends Request return $this->entity; } + $class = EntityModel::getClassName($this->entityType); + // The entity id can appear as invoices, invoice_id, public_id or id $publicId = false; $field = $this->entityType . '_id'; @@ -37,12 +39,14 @@ class EntityRequest extends Request return null; } - $class = EntityModel::getClassName($this->entityType); - if (method_exists($class, 'trashed')) { - $this->entity = $class::scope($publicId)->withTrashed()->firstOrFail(); + $this->entity = $class::scope($publicId)->withTrashed()->first(); } else { - $this->entity = $class::scope($publicId)->firstOrFail(); + $this->entity = $class::scope($publicId)->first(); + } + + if (! $this->entity) { + abort(404, "Entity: {$class} Id: {$publicId} not found"); } return $this->entity; diff --git a/app/Jobs/ImportData.php b/app/Jobs/ImportData.php index 4d0d5765ab69..2f2ba53c8828 100644 --- a/app/Jobs/ImportData.php +++ b/app/Jobs/ImportData.php @@ -91,7 +91,7 @@ class ImportData extends Job implements ShouldQueue } catch (Exception $exception) { $subject = trans('texts.import_failed'); $message = $exception->getMessage(); - Utils::logError($subject . ':' . $message); + Utils::logError($subject . ': ' . $message); } $userMailer->sendMessage($this->user, $subject, $message); diff --git a/app/Libraries/CurlUtils.php b/app/Libraries/CurlUtils.php index 79e9332f474c..7e699c226b94 100644 --- a/app/Libraries/CurlUtils.php +++ b/app/Libraries/CurlUtils.php @@ -63,7 +63,6 @@ class CurlUtils if ($response->getStatus() === 200) { return $response->getContent(); } else { - Utils::logError('Local PhantomJS Error: ' . $response->getStatus() . ' - ' . $url); return false; } } diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 3e07367344a9..6c461f1ec7c3 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -1168,10 +1168,17 @@ class Invoice extends EntityModel implements BalanceAffecting $link = $invitation->getLink('view', true); $pdfString = false; $phantomjsSecret = env('PHANTOMJS_SECRET'); + $phantomjsLink = $link . "?phantomjs=true&phantomjs_secret={$phantomjsSecret}"; try { if (env('PHANTOMJS_BIN_PATH')) { - $pdfString = CurlUtils::phantom('GET', $link . "?phantomjs=true&phantomjs_secret={$phantomjsSecret}"); + // we see occasional 408 errors + for ($i=1; $i<=5; $i++) { + $pdfString = CurlUtils::phantom('GET', $phantomjsLink); + if ($pdfString) { + break; + } + } } if (! $pdfString && ($key = env('PHANTOMJS_CLOUD_KEY'))) { @@ -1181,12 +1188,12 @@ class Invoice extends EntityModel implements BalanceAffecting $pdfString = strip_tags($pdfString); } catch (\Exception $exception) { - Utils::logError("PhantomJS - Failed to load: {$exception->getMessage()}"); + Utils::logError("PhantomJS - Failed to load {$phantomjsLink}: {$exception->getMessage()}"); return false; } if (! $pdfString || strlen($pdfString) < 200) { - Utils::logError("PhantomJS - Invalid response: {$pdfString}"); + Utils::logError("PhantomJS - Invalid response {$phantomjsLink}: {$pdfString}"); return false; } @@ -1194,7 +1201,7 @@ class Invoice extends EntityModel implements BalanceAffecting if ($pdf = Utils::decodePDF($pdfString)) { return $pdf; } else { - Utils::logError("PhantomJS - Unable to decode: {$pdfString}"); + Utils::logError("PhantomJS - Unable to decode {$phantomjsLink}: {$pdfString}"); return false; } } else { diff --git a/app/Models/LookupModel.php b/app/Models/LookupModel.php index 023287306bfc..291b26735817 100644 --- a/app/Models/LookupModel.php +++ b/app/Models/LookupModel.php @@ -96,7 +96,7 @@ class LookupModel extends Eloquent ->first(); } if (! $isFound) { - abort(500, "Looked up {$className} not found: {$field} => {$value}"); + abort(404, "Looked up {$className} not found: {$field} => {$value}"); } Cache::put($key, $server, 120);