Example #1
0
| Here you may handle any errors that occur in your application, including
| logging them or displaying custom views for specific errors. You may
| even register several error handlers to handle different types of
| exceptions. If nothing is returned, the default error view is
| shown, which includes a detailed stack trace during debug.
|
*/
App::error(function (Exception $exception, $code) {
    Log::error($exception);
    if (!Config::get('app.debug') && !App::runningInConsole()) {
        return Response::view('errors.500', array('code' => $code, 'exception' => $exception), $code);
    }
});
App::fatal(function (Exception $exception) {
    Log::error($exception);
    if (!Config::get('app.debug') && !App::runningInConsole()) {
        return Response::view('errors.500', array('code' => 'Fatal', 'exception' => $exception), 500);
    }
});
/*
|--------------------------------------------------------------------------
| Maintenance Mode Handler
|--------------------------------------------------------------------------
|
| The "down" Artisan command gives you the ability to put an application
| into maintenance mode. Here, you will define what is displayed back
| to the user if maintenance mode is in effect for the application.
|
*/
App::down(function () {
    return Response::view('errors.503', array(), 503);
});
Example #2
0
    $line = $exception->getLine();
    $file_in_db = $file;
    $line_in_db = $line;
    $fatal = 0;
    if (!Error::whereRaw("url = '{$url}' and code = '{$code}' and file = '{$file_in_db}' and line = {$line_in_db}")->exists()) {
        $type = str_contains($msg, "SQL") ? "mysql" : "php";
        Error::create(array('url' => url($url), 'code' => $code, 'msg' => $msg, 'file' => $file, 'line' => $line, 'fatal' => $fatal, 'type' => $type));
    }
});
App::fatal(function ($exception) {
    $url = Request::url();
    $code = $exception->getCode();
    $msg = $exception->getMessage();
    $file = $exception->getFile();
    $line = $exception->getLine();
    $file_in_db = $file;
    $line_in_db = $line;
    $fatal = 1;
    if (!Error::whereRaw("url = '{$url}' and code = '{$code}' and file = '{$file_in_db}' and line = {$line_in_db}")->exists()) {
        $type = str_contains($msg, "SQL") ? "mysql" : "php";
        Error::create(array('url' => url($url), 'code' => $code, 'msg' => $msg, 'file' => $file, 'line' => $line, 'fatal' => $fatal, 'type' => $type));
    }
});
App::missing(function ($exception) {
    $page_title = "page 404 :(";
    $article = Article::where('name', '=', '404')->get()->first();
    if (!$article) {
        return Response::view('frontend.article.alternative-404-page', compact('page_title'), 404);
    }
    return Response::view('frontend.article.index', compact('article', 'page_title'), 404);
});
/*
Example #3
0
<?php

use Illuminate\Database\Eloquent\ModelNotFoundException;
//以下内容只在产品环境下有效
$error = function (Exception $exception, $code = 500) {
    Log::error($exception);
    if (App::runningInConsole() || Request::is('api/*')) {
        return Response::json(array('succeed' => 0, 'error_code' => $code, 'error_desc' => '处理失败'));
    } else {
        return View::make($code);
    }
};
// 一般错误
App::error(function ($exception) use($error) {
    return $error($exception, 500);
});
// 404
App::missing(function ($exception) use($error) {
    return $error($exception, 404);
});
// 服务器内部错误
App::fatal(function ($exception) use($error) {
    return $error($exception, 500);
});
//模型未找到
App::error(function (ModelNotFoundException $exception) use($error) {
    return $error($exception, 404);
});
Example #4
0
File: routes.php Project: joadr/cms
<?php

Route::group(['namespace' => 'Cms\\Site\\Controllers'], function () {
    Route::get('js/app.js', ['as' => 'site.assets.appjs', 'uses' => 'AssetsController@getAppJs']);
    Route::get('api/definitions/', ['as' => 'api.definitions.index', 'uses' => 'DefinitionsController@index']);
    Route::get('api/{entity}/', ['as' => 'api.entity.index', 'uses' => 'EntitiesController@index']);
    Route::get('api/{entity}/{id}', ['as' => 'api.entity.show', 'uses' => 'EntitiesController@show']);
    $routes = \PublicRouteDriver::all();
    foreach ($routes as $route) {
        Route::get($route->laravel_format, ['as' => $route->name, 'uses' => 'SiteController@route']);
    }
    Route::get('sitemap.xml', ['as' => 'site.directory.sitemap', 'uses' => 'DirectoryController@sitemap']);
    Route::get('directory', ['as' => 'site.directory.index', 'uses' => 'DirectoryController@index']);
    Route::get('directory/{id}', ['as' => 'site.directory.depended', 'uses' => 'DirectoryController@depended']);
});
if (!Config::get('app.debug')) {
    App::error(function (\Exception $exception) {
        Log::error($exception);
        return Response::view('errors.unknown', array(), 500);
    });
    App::fatal(function ($exception) {
        Log::error($exception);
        return Response::view('errors.fatal', array(), 500);
    });
    App::missing(function ($exception) {
        return Response::view('errors.missing', array(), 404);
    });
}
Example #5
0
|
*/
App::down(function () {
    return Response::make("Be right back!", 503);
});
/*
|--------------------------------------------------------------------------
| Require The Filters File
|--------------------------------------------------------------------------
|
| Next we will load the filters file for the application. This gives us
| a nice separate location to store our route and application filter
| definitions instead of putting them all in the main routes file.
|
*/
App::singleton('bugsnag', function () {
    $bugsnag = new Bugsnag_Client(Config::get('app.bugsnag_api_key'));
    $bugsnag->setReleaseStage(App::environment());
    return $bugsnag;
});
App::error(function ($exception) {
    App::make('bugsnag')->notifyException($exception, null, "error");
});
App::fatal(function ($exception) {
    App::make('bugsnag')->notifyException($exception, null, "error");
});
App::make('bugsnag')->setUser(['email' => Auth::check() ? Auth::user()->email : 'Guest user']);
App::make('bugsnag')->setBeforeNotifyFunction(function ($error) {
    $error->setMetaData(["user" => ["username" => Auth::check() ? Auth::user()->username : '******'], "metrics" => ["Metric 1" => "Some data here"]]);
});
require app_path() . '/filters.php';
Example #6
0
    // Handle the runtime exception...
    $context = array("errorCode" => $exception->getCode());
    Log::error($exception, $context);
    // return Response::make('$exception->getMessage()', 404);
    return Response::view('exception.missing', array(), 404);
});
App::error(function (ErrorException $exception) {
    // Handle the error exception...
    $context = array("errorCode" => $exception->getCode());
    Log::error($exception, $context);
    return Response::view('exception.missing', array(), 404);
});
App::error(function (HttpException $exception, $code) {
    // Handle the http exception...
    $context = array("errorCode" => $code);
    Log::error($exception, $context);
    // return Response::make($exception->getMessage());
    return Response::view('exception.missing', array(), 404);
});
App::fatal(function ($exception) {
    // Handle the fatal exception...
    $context = array("errorCode" => $exception->getCode());
    Log::error($exception, $context);
    // return Response::make($exception->getMessage());
    return Response::view('exception.missing', array(), 404);
});
App::missing(function ($exception) {
    $context = array("errorCode" => $exception->getCode());
    Log::error($exception, $context);
    return Response::view('exception.missing', array(), 404);
});
Example #7
0
<?php

use Illuminate\Database\Eloquent\ModelNotFoundException;
$error = function (Exception $exception, $code = 500) {
    Log::error($exception);
    if (Request::ajax()) {
        return Response::json(array('error_code' => $code, 'error_desc' => $exception->getMessage() . ' at file' . $exception->getFile() . ' line:' . $exception->getLine()));
    } elseif (App::environment() == 'production') {
        return View::make($code);
    }
};
// 一般错误
App::error($error);
// 404
App::missing(function ($exception) use($error) {
    return $error($exception, 404);
});
// 服务器内部错误
App::fatal($error);
//模型未找到
App::error($error);