From f6b04a2335be4e1eba01d67424e2734dc290e8b6 Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Sat, 4 Jul 2020 16:15:59 +0500 Subject: [PATCH 1/5] code refector and improvements --- config/larvabug.php | 25 ++++++++++ src/Client/HttpClient.php | 63 +++++++++++++++++------- src/Commands/LarvaBugTestCommand.php | 14 ++++-- src/Handler/LarvaBugExceptionHandler.php | 7 ++- src/Handler/PrepareExceptionData.php | 11 +++-- 5 files changed, 93 insertions(+), 27 deletions(-) diff --git a/config/larvabug.php b/config/larvabug.php index 276ec99..3c9baf0 100644 --- a/config/larvabug.php +++ b/config/larvabug.php @@ -2,16 +2,41 @@ return [ + /* + * Id of project from larvabug.com + * + */ 'project_id' => env('LB_PROJECT_ID',''), + /* + * Project secret from larvabug.com + * + */ 'project_secret' => env('LB_SECRET',''), + /* + * Array of environments to enable error reporting + * If environment configured in the array will match with the laravel app environment + * then error will be reported to larvabug.com + * + */ 'environment' => ['production','local'], + /* + * Mention any error that should skip from reporting to laravbug + * Must be mentioned as a string + * + */ 'skip_errors' => [ '\Symfony\Component\HttpKernel\Exception\NotFoundHttpException::class' ], + /* + * Add request parameters to be black listed + * any parameter defined here will not be reported to larvabug.com and + * all request, session and cookies will be filtered + * + */ 'blacklist' => [ 'password' ] diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php index 3beb1ea..107d1e2 100644 --- a/src/Client/HttpClient.php +++ b/src/Client/HttpClient.php @@ -17,13 +17,15 @@ class HttpClient */ private $projectSecret; - private const URL = 'http://larvabug.local/api/v1/exception'; + //Development + private const POST_EXCEPTION = 'http://dev.larvabug.com/api/v1/exception'; + private const VALIDATE_CREDENTIALS = 'http://dev.larvabug.com/api/validate/credentials'; /** * @param string $projectId * @param string $projectSecret */ - public function __construct(string $projectId, string $projectSecret) + public function __construct(string $projectId = null, string $projectSecret = null) { $this->projectId = $projectId; $this->projectSecret = $projectSecret; @@ -39,24 +41,14 @@ public function report($exceptionData) try { $data_string = json_encode($exceptionData); - $header = [ - 'Content-Type:application/json', - 'Authorization-APP:' . $this->projectId, - 'Authorization-KEY:' . $this->projectSecret - ]; + $result = $this->postRequest($data_string,self::POST_EXCEPTION); - $ch = curl_init(self::URL); - - curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); - curl_setopt($ch, CURLOPT_HTTPHEADER, $header); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - $result = curl_exec($ch); - - curl_close($ch); - - if ($result && $result != 404){ - Session::put('lb.lastExceptionId', $result); + if ($result && + isset($result['status']) && + isset($result['exceptionId']) && + $result['status'] == 200 + ){ + Session::put('lb.lastExceptionId', $result['exceptionId']); } return true; @@ -65,4 +57,37 @@ public function report($exceptionData) } } + public function validateCredentials(array $credentials) + { + $result = $this->postRequest($credentials,self::VALIDATE_CREDENTIALS); + + if ($result && isset($result['status']) && $result['status'] == 200){ + return true; + } + + return false; + + } + + private function postRequest($requestData, $url) + { + $header = [ + 'Content-Type:application/json', + 'Authorization-APP:' . $this->projectId, + 'Authorization-KEY:' . $this->projectSecret + ]; + + $ch = curl_init($url); + + curl_setopt($ch, CURLOPT_POSTFIELDS, $requestData); + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + $result = curl_exec($ch); + + curl_close($ch); + + return $result; + } + } \ No newline at end of file diff --git a/src/Commands/LarvaBugTestCommand.php b/src/Commands/LarvaBugTestCommand.php index a43f5ce..246b401 100644 --- a/src/Commands/LarvaBugTestCommand.php +++ b/src/Commands/LarvaBugTestCommand.php @@ -51,11 +51,17 @@ public function handle() $this->info('2. ✗ [Larvabug] Could not find LarvaBug secret, please set this in your .env'); } + $requestData = [ + 'projectId' => config('larvabug.project_id'), + 'projectSecret' => config('larvabug.project_secret') + ]; - } - - public function testCredentials() - { + if (app('larvabug') && app('larvabug')->validateCredentials($requestData)){ + $this->info('3. ✓ [Larvabug] Validation Success'); + }else{ + $this->info('3. ✗ [Larvabug] Project id and secret do not match our records'); + } } + } \ No newline at end of file diff --git a/src/Handler/LarvaBugExceptionHandler.php b/src/Handler/LarvaBugExceptionHandler.php index d4f03bf..056ee3f 100644 --- a/src/Handler/LarvaBugExceptionHandler.php +++ b/src/Handler/LarvaBugExceptionHandler.php @@ -53,7 +53,7 @@ public function handle(\Throwable $exception) * * @return bool */ - public function checkAppEnvironment() + private function checkAppEnvironment() { if (!config('larvabug.environment')){ return false; @@ -80,4 +80,9 @@ protected function skipError($class) return false; } + + public function validateCredentials(array $credentials) + { + return $this->client->validateCredentials($credentials); + } } \ No newline at end of file diff --git a/src/Handler/PrepareExceptionData.php b/src/Handler/PrepareExceptionData.php index da1c1e3..88740c6 100644 --- a/src/Handler/PrepareExceptionData.php +++ b/src/Handler/PrepareExceptionData.php @@ -45,15 +45,20 @@ private function getExceptionData(\Throwable $exception) $data['exception'] = $exception->getMessage(); $data['class'] = get_class($exception); $data['file'] = $exception->getFile(); - $data['enviroment'] = App::environment(); + $data['php_version'] = PHP_VERSION; + $data['server_ip'] = $_SERVER['SERVER_ADDR'] ?? null; + $data['environment'] = App::environment(); $data['server_name'] = @gethostname(); $data['browser'] = $this->getUserBrowser(); $data['userOs'] = $this->getUserOS(); $data['host'] = Request::server('SERVER_NAME'); $data['method'] = Request::method(); $data['fullUrl'] = Request::fullUrl(); + $data['url'] = Request::path(); + $data['userIp'] = Request::ip(); $data['line'] = $exception->getLine(); - $data['date_time'] = date("Y-m-d H:i:s");; + $data['date_time'] = date("Y-m-d H:i:s"); + $data['session_id'] = Session::getId(); $data['storage'] = [ 'SERVER' => [ 'USER' => Request::server('USER'), @@ -79,7 +84,7 @@ private function getExceptionData(\Throwable $exception) $count = config('larvabug.lines_count'); if (!$count || $count > 12) { - $count = 5; + $count = 10; } $lines = file($data['file']); From 2539d4085726440e6678842be36deda7756e20de Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Mon, 6 Jul 2020 19:27:46 +0500 Subject: [PATCH 2/5] some issue fixed and code refactored --- resources/views/analytics.blade.php | 8 + resources/views/feedback.blade.php | 517 ++++++++++++++++++ routes/api.php | 3 + routes/web.php | 1 - src/Client/HttpClient.php | 47 +- src/Commands/LarvaBugTestCommand.php | 14 +- src/Facade/LarvaBug.php | 4 + src/Handler/LarvaBugExceptionHandler.php | 72 ++- src/Handler/PrepareExceptionData.php | 5 + .../Controllers/LarvaBugMainController.php | 37 ++ src/Provider/BootServices.php | 39 +- src/Provider/ServiceProvider.php | 6 + 12 files changed, 737 insertions(+), 16 deletions(-) create mode 100644 resources/views/analytics.blade.php create mode 100644 resources/views/feedback.blade.php delete mode 100644 routes/web.php create mode 100644 src/Http/Controllers/LarvaBugMainController.php diff --git a/resources/views/analytics.blade.php b/resources/views/analytics.blade.php new file mode 100644 index 0000000..b1c3474 --- /dev/null +++ b/resources/views/analytics.blade.php @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/resources/views/feedback.blade.php b/resources/views/feedback.blade.php new file mode 100644 index 0000000..b98624a --- /dev/null +++ b/resources/views/feedback.blade.php @@ -0,0 +1,517 @@ + + + 500 Server Error + + + +
+

500 :(

+

Seems Like we have an internal issue, Please tell us more to batter understand the issue

+
+
+
+
+ + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
    +
+
+
+
+
+
+
+
+ + + Powered By: LarvaBug + + + + diff --git a/routes/api.php b/routes/api.php index b3d9bbc..e4df666 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1 +1,4 @@ setLastExceptionId($result['exceptionId']); } return true; @@ -57,9 +60,16 @@ public function report($exceptionData) } } + /** + * Validate env project id and secret + * + * @param array $credentials + * @return bool + * @author Syed Faisal + */ public function validateCredentials(array $credentials) { - $result = $this->postRequest($credentials,self::VALIDATE_CREDENTIALS); + $result = $this->postRequest(json_encode($credentials),self::VALIDATE_CREDENTIALS); if ($result && isset($result['status']) && $result['status'] == 200){ return true; @@ -69,6 +79,13 @@ public function validateCredentials(array $credentials) } + /** + * Curl Request + * + * @param $requestData + * @param $url + * @return bool|mixed + */ private function postRequest($requestData, $url) { $header = [ @@ -87,7 +104,29 @@ private function postRequest($requestData, $url) curl_close($ch); - return $result; + if ($result) { + return json_decode($result, true); + } + + return false; + } + + /** + * Submit last exception feedback + * + * @param $data + * @return bool + */ + public function submitFeedback($data) + { + $result = $this->postRequest(json_encode($data),self::POST_FEEDBACK); + + if ($result && isset($result['status']) && $result['status'] == 200){ + return true; + } + + return false; + } } \ No newline at end of file diff --git a/src/Commands/LarvaBugTestCommand.php b/src/Commands/LarvaBugTestCommand.php index 246b401..f7eeb85 100644 --- a/src/Commands/LarvaBugTestCommand.php +++ b/src/Commands/LarvaBugTestCommand.php @@ -39,21 +39,21 @@ public function handle() { $this->info('Testing LarvaBug Configurations'); - if (config('larvabug.project_id')){ + if (env('LB_PROJECT_ID') && !is_null(env('LB_PROJECT_ID'))){ $this->info('1. ✓ [Larvabug] Found project id'); }else{ $this->info('1. ✗ [Larvabug] Could not find your project id, please set this in your .env'); } - if (config('larvabug.project_secret')){ + if (env('LB_SECRET') && !is_null(env('LB_SECRET'))){ $this->info('2. ✓ [Larvabug] Found secret key'); }else{ $this->info('2. ✗ [Larvabug] Could not find LarvaBug secret, please set this in your .env'); } $requestData = [ - 'projectId' => config('larvabug.project_id'), - 'projectSecret' => config('larvabug.project_secret') + 'projectId' => env('LB_PROJECT_ID'), + 'projectSecret' => env('LB_SECRET') ]; if (app('larvabug') && app('larvabug')->validateCredentials($requestData)){ @@ -62,6 +62,12 @@ public function handle() $this->info('3. ✗ [Larvabug] Project id and secret do not match our records'); } + try { + + }catch (\Exception $exception){ + throw $exception; + } + } } \ No newline at end of file diff --git a/src/Facade/LarvaBug.php b/src/Facade/LarvaBug.php index c48de7d..b64a8af 100644 --- a/src/Facade/LarvaBug.php +++ b/src/Facade/LarvaBug.php @@ -8,6 +8,10 @@ class LarvaBug extends FacadeAlias { + /** + * @return string + * + */ protected static function getFacadeAccessor() { return 'larvabug'; diff --git a/src/Handler/LarvaBugExceptionHandler.php b/src/Handler/LarvaBugExceptionHandler.php index 056ee3f..1e63fc3 100644 --- a/src/Handler/LarvaBugExceptionHandler.php +++ b/src/Handler/LarvaBugExceptionHandler.php @@ -4,6 +4,9 @@ namespace LarvaBug\Handler; use Illuminate\Support\Facades\App; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Session; +use Illuminate\Support\Facades\URL; use LarvaBug\Client\HttpClient; class LarvaBugExceptionHandler @@ -16,6 +19,10 @@ class LarvaBugExceptionHandler * @var PrepareExceptionData */ private $exceptionData; + /** + * @var string + */ + private $lastExceptionId; /** * LarvaBugExceptionHandler constructor. @@ -31,7 +38,7 @@ public function __construct( $this->exceptionData = $exceptionData; } - public function handle(\Throwable $exception) + public function report(\Throwable $exception) { if (!$this->checkAppEnvironment()){ return false; @@ -72,7 +79,13 @@ private function checkAppEnvironment() return false; } - protected function skipError($class) + /** + * Error dont report, configured in config file + * + * @param $class + * @return bool + */ + private function skipError($class) { if (in_array($class,config('larvabug.skip_errors'))){ return true; @@ -81,8 +94,63 @@ protected function skipError($class) return false; } + /** + * Validate env credentials from larvabug + * + * @param array $credentials + * @return bool + */ public function validateCredentials(array $credentials) { return $this->client->validateCredentials($credentials); } + + /** + * Collect error feedback from user + * + * @return \Illuminate\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector + */ + public function collectFeedback() + { + if ($this->lastExceptionId) { + return redirect($this->feedbackUrl().'?exceptionId='.$this->lastExceptionId); + } + + return redirect('/'); + } + + /** + * Get feedback url + * + * @return mixed + * @author Syed Faisal + */ + public function feedbackUrl() + { + return URL::to('larvabug-api/collect/feedback'); + } + + /** + * Submit user collected feedback + * + * @param $data + * @return bool + */ + public function submitFeedback($data) + { + $this->client->submitFeedback($data); + + return true; + } + + public function setLastExceptionId(string $exceptionId) + { + return $this->lastExceptionId = $exceptionId; + } + + public function getLastExceptionId() + { + return $this->lastExceptionId; + } + } \ No newline at end of file diff --git a/src/Handler/PrepareExceptionData.php b/src/Handler/PrepareExceptionData.php index 88740c6..92335cc 100644 --- a/src/Handler/PrepareExceptionData.php +++ b/src/Handler/PrepareExceptionData.php @@ -161,6 +161,11 @@ private function prepareTraceData($trace): array return $response; } + /** + * get auth user if exists + * + * @return |null + */ private function getAuthUser() { if (function_exists('auth') && auth()->check()) { diff --git a/src/Http/Controllers/LarvaBugMainController.php b/src/Http/Controllers/LarvaBugMainController.php new file mode 100644 index 0000000..d7c20a0 --- /dev/null +++ b/src/Http/Controllers/LarvaBugMainController.php @@ -0,0 +1,37 @@ +submitFeedback($data); + + return Redirect::to('/'); + } + + /** + * Collect feedback view + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\Foundation\Application|\Illuminate\View\View + */ + public function postFeedback() + { + return view('larvabug::feedback'); + } + +} \ No newline at end of file diff --git a/src/Provider/BootServices.php b/src/Provider/BootServices.php index ee20ad6..381356e 100644 --- a/src/Provider/BootServices.php +++ b/src/Provider/BootServices.php @@ -4,27 +4,53 @@ namespace LarvaBug\Provider; +use Illuminate\Support\Facades\Route; use LarvaBug\Commands\LarvaBugTestCommand; trait BootServices { + /** + * List of commands to be registered along with provider + * + * @var string[] + */ protected $commands = [ LarvaBugTestCommand::class ]; - protected function bootServices() + /** + * BootServices method contains all service that needs to be registered + */ + private function bootServices() { $this->publishConfig(); $this->registerView(); $this->registerCommands(); + $this->mapLaraBugApiRoutes(); } - protected function registerView() + /** + * Register view directory with larvabug namespace + */ + private function registerView() { - $this->app['view']->addNamespace('larvabug',__DIR__.'../../resources/views'); + $this->app['view']->addNamespace('larvabug',__DIR__.'/../../resources/views'); } - protected function publishConfig() + /** + * Map api routes directory to enable all api routes for larvabug + */ + private function mapLaraBugApiRoutes() + { + Route::namespace('\LarvaBug\Http\Controllers') + ->prefix('larvabug-api') + ->group(__DIR__ . '/../../routes/api.php'); + } + + /** + * Publish package config files that contains package configurations + */ + private function publishConfig() { if (function_exists('config_path')) { $this->publishes([ @@ -33,7 +59,10 @@ protected function publishConfig() } } - public function registerCommands() + /** + * Register array of commands + */ + private function registerCommands() { $this->commands($this->commands); } diff --git a/src/Provider/ServiceProvider.php b/src/Provider/ServiceProvider.php index 0e846cb..3eb05dd 100644 --- a/src/Provider/ServiceProvider.php +++ b/src/Provider/ServiceProvider.php @@ -13,11 +13,17 @@ class ServiceProvider extends BaseServiceProvider { use BootServices; + /** + * boot method of service provider + */ public function boot() { $this->bootServices(); } + /** + * Register method of service provider + */ public function register() { $this->app->singleton('larvabug',function ($app){ From 8603678ae6291e8a2941448fc659846cbea49264 Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Tue, 7 Jul 2020 21:31:04 +0500 Subject: [PATCH 3/5] Log functionality added --- src/Client/HttpClient.php | 11 +++- src/Handler/LarvaBugExceptionHandler.php | 47 +++++++++++--- src/Handler/PrepareExceptionData.php | 80 ++++++++++++++---------- 3 files changed, 95 insertions(+), 43 deletions(-) diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php index 78c3552..ab4310f 100644 --- a/src/Client/HttpClient.php +++ b/src/Client/HttpClient.php @@ -18,10 +18,15 @@ class HttpClient */ private $projectSecret; + //Local + private const POST_EXCEPTION = 'http://larvabug.local/api/v1/exception'; + private const VALIDATE_CREDENTIALS = 'http://larvabug.local/api/v1/validate/credentials'; + private const POST_FEEDBACK = 'http://larvabug.local/api/v1/feedback/submit'; + //Development - private const POST_EXCEPTION = 'http://dev.larvabug.com/api/v1/exception'; - private const VALIDATE_CREDENTIALS = 'http://dev.larvabug.com/api/v1/validate/credentials'; - private const POST_FEEDBACK = 'http://dev.larvabug.com/api/v1/feedback/submit'; +// private const POST_EXCEPTION = 'http://dev.larvabug.com/api/v1/exception'; +// private const VALIDATE_CREDENTIALS = 'http://dev.larvabug.com/api/v1/validate/credentials'; +// private const POST_FEEDBACK = 'http://dev.larvabug.com/api/v1/feedback/submit'; /** diff --git a/src/Handler/LarvaBugExceptionHandler.php b/src/Handler/LarvaBugExceptionHandler.php index 1e63fc3..cf6a418 100644 --- a/src/Handler/LarvaBugExceptionHandler.php +++ b/src/Handler/LarvaBugExceptionHandler.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\URL; use LarvaBug\Client\HttpClient; @@ -38,21 +39,53 @@ public function __construct( $this->exceptionData = $exceptionData; } + /** + * Report exception to larvabug + * + * @param \Throwable $exception + * @return bool + */ public function report(\Throwable $exception) { - if (!$this->checkAppEnvironment()){ - return false; - } + try { + if (!$this->checkAppEnvironment()) { + return false; + } + + if ($this->skipError(get_class($exception))) { + return false; + } + + $data = $this->exceptionData->prepareException($exception); - if ($this->skipError(get_class($exception))){ + $this->client->report($data); + + return true; + }catch (\Exception $exception){ + Log::info('Lavabug Exception :'.$exception->getMessage()); return false; } + } - $data = $this->exceptionData->prepare($exception); + /** + * Log details to larvabug + * + * @param $message + * @param array $meta + * @return bool + */ + public function log($message, array $meta = []) + { + try { + $data = $this->exceptionData->prepareLogData($message, $meta); - $this->client->report($data); + $this->client->report($data); - return true; + return true; + }catch (\Exception $exception){ + Log::info('Lavabug Exception :'.$exception->getMessage()); + return false; + } } /** diff --git a/src/Handler/PrepareExceptionData.php b/src/Handler/PrepareExceptionData.php index 92335cc..936f79d 100644 --- a/src/Handler/PrepareExceptionData.php +++ b/src/Handler/PrepareExceptionData.php @@ -27,9 +27,53 @@ public function __construct() * @author Syed Faisal * @param \Throwable $exception */ - public function prepare(\Throwable $exception) + public function prepareException(\Throwable $exception) { - return $this->getExceptionData($exception); + $data = $this->getRequestInfo($exception); + + $data['exception'] = $exception->getMessage(); + $data['class'] = get_class($exception); + $data['file'] = $exception->getFile(); + $data['line'] = $exception->getLine(); + $data['error'] = $exception->getTraceAsString(); + $data['trace_with_details'] = $this->prepareTraceData($exception->getTrace()); + + $count = config('larvabug.lines_count'); + + if (!$count || $count > 12) { + $count = 10; + } + + $lines = file($data['file']); + $data['executor'] = []; + + for ($i = -1 * abs($count); $i <= abs($count); $i++) { + $data['executor'][] = $this->getLineInfo($lines, $data['line'], $i); + } + + $data['executor'] = array_filter($data['executor']); + + // to make symfony exception more readable + if ($data['class'] == 'Symfony\Component\Debug\Exception\FatalErrorException') { + preg_match("~^(.+)' in ~", $data['exception'], $matches); + if (isset($matches[1])) { + $data['exception'] = $matches[1]; + } + } + + return $data; + } + + public function prepareLogData(string $message,array $meta = []) + { + $data = $this->getRequestInfo(); + $data['exception'] = $message; + $data['class'] = 'Log Information'; + $data['type'] = 'log'; + $data['meta_data'] = $meta; + + return $data; + } /** @@ -38,13 +82,10 @@ public function prepare(\Throwable $exception) * @param \Throwable $exception * @return array */ - private function getExceptionData(\Throwable $exception) + private function getRequestInfo() { $data = []; - $data['exception'] = $exception->getMessage(); - $data['class'] = get_class($exception); - $data['file'] = $exception->getFile(); $data['php_version'] = PHP_VERSION; $data['server_ip'] = $_SERVER['SERVER_ADDR'] ?? null; $data['environment'] = App::environment(); @@ -56,7 +97,6 @@ private function getExceptionData(\Throwable $exception) $data['fullUrl'] = Request::fullUrl(); $data['url'] = Request::path(); $data['userIp'] = Request::ip(); - $data['line'] = $exception->getLine(); $data['date_time'] = date("Y-m-d H:i:s"); $data['session_id'] = Session::getId(); $data['storage'] = [ @@ -76,34 +116,8 @@ private function getExceptionData(\Throwable $exception) 'HEADERS' => $this->filterBlackList(Request::header()), ]; $data['auth_user'] = $this->getAuthUser(); - $data['error'] = $exception->getTraceAsString(); - $data['trace_with_details'] = $this->prepareTraceData($exception->getTrace()); - $data['storage'] = array_filter($data['storage']); - $count = config('larvabug.lines_count'); - - if (!$count || $count > 12) { - $count = 10; - } - - $lines = file($data['file']); - $data['executor'] = []; - - for ($i = -1 * abs($count); $i <= abs($count); $i++) { - $data['executor'][] = $this->getLineInfo($lines, $data['line'], $i); - } - - $data['executor'] = array_filter($data['executor']); - - // to make symfony exception more readable - if ($data['class'] == 'Symfony\Component\Debug\Exception\FatalErrorException') { - preg_match("~^(.+)' in ~", $data['exception'], $matches); - if (isset($matches[1])) { - $data['exception'] = $matches[1]; - } - } - return $data; } From 4eba07d6a65a8c6f9e3836bafe36f9fff4fb4c5c Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Wed, 8 Jul 2020 17:48:09 +0500 Subject: [PATCH 4/5] uncomment development url --- src/Client/HttpClient.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Client/HttpClient.php b/src/Client/HttpClient.php index ab4310f..181dbaa 100644 --- a/src/Client/HttpClient.php +++ b/src/Client/HttpClient.php @@ -19,14 +19,14 @@ class HttpClient private $projectSecret; //Local - private const POST_EXCEPTION = 'http://larvabug.local/api/v1/exception'; - private const VALIDATE_CREDENTIALS = 'http://larvabug.local/api/v1/validate/credentials'; - private const POST_FEEDBACK = 'http://larvabug.local/api/v1/feedback/submit'; +// private const POST_EXCEPTION = 'http://larvabug.local/api/v1/exception'; +// private const VALIDATE_CREDENTIALS = 'http://larvabug.local/api/v1/validate/credentials'; +// private const POST_FEEDBACK = 'http://larvabug.local/api/v1/feedback/submit'; //Development -// private const POST_EXCEPTION = 'http://dev.larvabug.com/api/v1/exception'; -// private const VALIDATE_CREDENTIALS = 'http://dev.larvabug.com/api/v1/validate/credentials'; -// private const POST_FEEDBACK = 'http://dev.larvabug.com/api/v1/feedback/submit'; + private const POST_EXCEPTION = 'http://dev.larvabug.com/api/v1/exception'; + private const VALIDATE_CREDENTIALS = 'http://dev.larvabug.com/api/v1/validate/credentials'; + private const POST_FEEDBACK = 'http://dev.larvabug.com/api/v1/feedback/submit'; /** @@ -134,4 +134,4 @@ public function submitFeedback($data) } -} \ No newline at end of file +} From 7118704a265100a7b008835feae56355c6c9b5bb Mon Sep 17 00:00:00 2001 From: Syed Faisal Kazmi Date: Wed, 8 Jul 2020 18:42:58 +0500 Subject: [PATCH 5/5] Fixed Path --- src/Commands/LarvaBugTestCommand.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Commands/LarvaBugTestCommand.php b/src/Commands/LarvaBugTestCommand.php index f7eeb85..b764737 100644 --- a/src/Commands/LarvaBugTestCommand.php +++ b/src/Commands/LarvaBugTestCommand.php @@ -3,6 +3,7 @@ namespace LarvaBug\Commands; use Illuminate\Console\Command; +use LarvaBug\Facade\LarvaBug; class LarvaBugTestCommand extends Command { @@ -62,10 +63,10 @@ public function handle() $this->info('3. ✗ [Larvabug] Project id and secret do not match our records'); } - try { - + try{ + throw new \Exception('Larvabug Test Exception'); }catch (\Exception $exception){ - throw $exception; + LarvaBug::report($exception); } }