How to use Errbit in Laravel 4? - php

I just install the Errbit in my PC using ruby, and it's already running on my local. And I developed a web apps using Laravel 4, but I didn't know how can I send all of the errors of my web apps to the errbit.I already installed this package, but I didn't know how to implement this on my web apps.
I already tried to use below script on my ../app/start/global.php on Applicatoin Error Handler, but it's only show me the white page. This is my script:
<?php
...
App::error(function(Exception $exception, $code)
{
Errbit::instance()->notify($exception);
Log::error($exception);
});
...
And this is how I create an error in my controller, I remove the semicolon delimeter like this:
<?php
class someController extends \BaseController {
public function index(){
return View::make('editor.index') //Remove ';' at the end of line code
}
}
If I remove the errbit instance Errbit::instance()->notify($exception); on global.php, the page will return Whoops error from laravel, but if I add errbit instance, it's only show the blank white page, and nothing happend to the errbit report.
And also I already tried to put the errbit on the method of controller like below, but I still get nothing.
<?php
public function index(){
try {
return View::make('editor.index')
} catch (Exception $e) {
Errbit::instance()->notify($e);
}
}
Please help me, and thanks before.

Related

Lumen shows blank page instead of showing an error on blade

I came across with interesting problem,
I am using lumen on my windows localhost, the problem is while I write incorrect code or syntax error in my view/blade, lumen shows blank page instead of error. However, in controller or another page I am able to debug my code, It shows error.
Error debugging is open in php.ini.
APP_DEBUG=true in my project.
I have tried to fresh install, still same.
Edit app/Exceptions/Handler.php file , method render
e.g. make something like this:
public function render($request, Throwable $exception)
{
if (env('APP_DEBUG')) {
dd($exception);
}
return parent::render($request, $exception);
}
or you can grab it as it is instanceof Illuminate\View\ViewException

Laravel 5 blade shows a blank page when there is error instead of throwing exception

In laravel 4 when you try to render a view that does not exists in app\views or a view with undefined variables laravel will throw an exception or show error that helps with debug.
I have a fresh installation of laravel 5.0.13 and am having a tough time troubleshooting a blade template that shows a blank page when i render a view that does not exists instead or a template with undefined variables instead of throwing an exception or error which will clue me in when debug.
I have installed filp/whoops:~1.0. but still recieve a blank page
class ProfileController extends Controller
{
public function index()
{
return view('indexx'); //this view does not really exist
}
}
The file indexx does not exist in my resources/views and i expect Laravel to throw an exception but am getting a blank page instead, why?
Also when i render a view that exists with some undefined variables i simply get a blank page
Example:
class ProfileController extends Controller
{
public function index()
{
return view('index'); //this view exists
}
}
The content of resources/views/index
{!! $this_variable_was_not_passed_an_I_expect_error !!}
As you can see in the view file above the variable does not exist by laravel will simply show a blank page instead of throwing an exception or some debug error.
Also to note i change my laravel default view in config/views
'paths' => [
//realpath(base_path('resources/views'))
realpath(base_path('resources/themes/default'))
],
And laravel was able to render views from resources/themes/default as long as there is no error in the template however, if any error was encountered such ar undefined variable a laravel displays a blank page instead of showing error message
Also to mention that I install virtual box and vagrant on window 7
Could this be a bug or something? Please assist.
Try to change permission on the storage folder:
chmod -R 0777 storage
It worked for me.
I don't really know why this happened but its now working as required after i run
vagrant destroy to destroy homestead VM
and then vagrant up - to create the VM
The error messages has now showing up instead of blank page:
An alternative solution which helped me, is running
composer install
I deployed with git which auto ignores some files. running composer install fixed it for me.
I got the same problem but here comes the reason and the solution:
The logfiles in storage/logs needs to be owned/writable by the webserver user. Otherwise L5 gives you a blank page.
I run "php artisan ..." always as root. If an exception was thrown and Laravel creates a new logfile, then it's owned by root. On my Debian i run in the project root folder:
chown www-data.root * -R
to solve this problem.
//lavarel 4
* Add this to app/start/gobal.php
App::error(function(Exception $e, $code) {
$runner = new \Whoops\Run;
$inspect = new \Whoops\Exception\Inspector($e);
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setRun($run);
$handler->setInspector($insp);
$handler->setException($e);
return $handler->handle($e);
});
//lavarel 5
* Add this to app/Exceptions/Handler.php
public function render($request, Exception $exception)
{
..........
$runner = new \Whoops\Run;
$inspect = new \Whoops\Exception\Inspector($e);
$handler = new \Whoops\Handler\PrettyPageHandler;
$handler->setRun($run);
$handler->setInspector($insp);
$handler->setException($e);
$handler->handle($e);
......
return parent::render($request, $e);
}

Laravel redirecting and stopping the app

I'm trying to do a redirect from my service class. I don't want to return the url to the caller because it's not being accessed directly from controller and it should return other data in some cases.
However I found that i can do the redirect this way:
Redirect::away('http://someexternalurl.com')->send();
This seems to work fine - the user gets redirected to the url I entered. The problem is that in this case the app "lives on" so following commands get executed. That's not what I need.
If I die(); immediately after that my session changes don't seem to be "saved".
Is there a way to make a redirect and stop the App immediately after that without simply "killing" it?
Basically is there a way to rewrite this code
Session::forget('myval');
Redirect::away('http://someexternalurl.com')->send();
mail('my#mail.com', 'Test', 'Still running');
So that myval would be gone from the session, the user would be redirected to the url and mail would not be sent (actually anything after the redirect shouldn't be executed)?
Thank you
The solution is to throw an Exception and adapt the render method of the Exception Handler.
In Your Controller:
// app/Controllers/DashboardController.php
public function index()
{
\App\Services\Test::test();
return view('dashboard');
}
My example service :
// app/Services/Test.php
<?php
namespace App\Services;
class Test {
public static function test() {
throw new \App\Exceptions\TestException('test');
}
}
In your Exception Handler :
// app/Exceptions/Handler.php
public function render($request, Exception $exception)
{
if ($exception instanceof TestException) {
return redirect(url('/?error=' . $exception->getMessage()));
}
return parent::render($request, $exception);
}
My example Exception (you can name it whatever you want), it just needs to extend the default Exception.
<?php
namespace App\Exceptions;
class TestException extends \Exception {
}
It looks like you just need to return on you Redirect?
return Redirect::away('http://someexternalurl.com')->send();
Here's the solution for Laravel 5.2. I reckon it would be work at all 5.*
abort(301, '', ['Location' => 'http://antondukhanin.ru']);
methodThatWouldntBeExecuted();
the function throws HttpException, so that will interrupt execution of any next commands

Print invoice button gives blank page with error

I want to print the invoice through the back-end of magento at invoices but it gives me this error after I turned on the errors in index.php
Fatal error: Call to a member function getPdf() on a non-object in app/code/core/Mage/Adminhtml/Controller/Sales/Invoice.php on line 119
public function printAction()
{
if ($invoiceId = $this->getRequest()->getParam('invoice_id')) {
if ($invoice = Mage::getModel('sales/order_invoice')->load($invoiceId)) {
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
$this->_prepareDownloadResponse('invoice'.Mage::getSingleton('core/date')->date('Y-m-d_H-i-s').
'.pdf', $pdf->render(), 'application/pdf');
}
}
else {
$this->_forward('noRoute');
}
}
The error says that this line:
$pdf = Mage::getModel('sales/order_pdf_invoice')->getPdf(array($invoice));
contains an error but I don't see any problem also I don't get it why it gives error on a core folder php file. I haven't modify it in any way too.
First, tell which version of Magento you are using?
Meanwhile, you may try the following:
disable all the installed extensions, and when enabling them one by one, figure out which module is triggering the issue;
clear cache.
Magento uses old Zend PDF library which has an issue:
http://framework.zend.com/issues/browse/ZF-12093
Just comment
//abstract public function __construct();
//abstract public function __destruct();
in
app\code\local\Zend\Pdf\FileParserDataSource.php.

Kohana 404 custom page

I have been looking around and following each tutorials,there is one which stands out. http://blog.lysender.com/2011/02/kohana-3-1-migration-custom-error-pages/ <-- i followed this tutorial and everything went smoothly
the error is being detected
the exception is being handled
but there has been an exception that i cant seem to find. im currently having this exception
Fatal error: Exception thrown without a stack frame in Unknown on line 0
all of my codes are thesame to the site-link. please help me.. im bugging around for this since ever, i've looked through here also Kohana 3 - redirect to 404 page but since im a beginner, its really hard understanding it. I've also found out that there is a major revamp from KO 3.0 to 3.1 how about KO 3.2? Thank you for your help guys :)
From the kohana source-code.
- > If you receive *Fatal error: Exception thrown without a stack frame in Unknown on line 0*, it means there was an error within your exception handler. If using the example above, be sure *404.php* exists under */application/views/error/*.
Maybe it helps. This probably has been fixed, but I'm not following the kohana development that much. It's related to pull request #246: https://github.com/kohana/core/pull/246 and this is the source: https://github.com/kohana/core/pull/246/files#L208L76
here is how I do it with Kohana 3.2
Add exceptions handling stuff in index.php
try
{
$request = $request->execute();
}
catch(Kohana_HTTP_Exception_404 $e)
{
$request = Request::factory('errors/404')->execute();
}
catch(Exception $e)
{
$request = Request::factory('errors/500')->execute();
}
echo $request->send_headers()->body();
Then write Errors controller
class Controller_Errors extends Controller
{
public function __construct($request, $response)
{
parent::__construct($request, $response);
}
public function action_404()
{
$this->response->body(View::factory('errors/404'));
}
public function action_500()
{
$this->response->body(View::factory('errors/500'));
}
}
Create 2 corresponding error pages (404.php and 500.php in views/errors)
Add new route to your bootstrap.php or use default one (depends on you project's structure), just make sure Controller_Errors can be reached when exception is thrown
Now every time you throws the exception in your controller, it will display the custom error page, like this
throw new HTTP_Exception_404;

Categories