Clean up error logs

This commit is contained in:
Hillel Coren 2017-08-16 10:28:40 +03:00
parent d31f23dcd3
commit 4eb3f58aec
7 changed files with 27 additions and 13 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -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;

View File

@ -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);

View File

@ -63,7 +63,6 @@ class CurlUtils
if ($response->getStatus() === 200) {
return $response->getContent();
} else {
Utils::logError('Local PhantomJS Error: ' . $response->getStatus() . ' - ' . $url);
return false;
}
}

View File

@ -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 {

View File

@ -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);