Skip to content

Commit 992b976

Browse files
authored
Merge pull request #8 from maloun96/telescop_exception
Add telescopeException
2 parents 40a76cd + 9482b3a commit 992b976

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

config/laravel-developer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@
2323
'auth' => [
2424
'bearer' => 'testing',
2525
],
26+
27+
'interacts_telescope' => env('INTERACTS_TELESCOPE'),
2628
];

src/Notifications/Slack.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Binarcode\LaravelDeveloper\Dtos\DevNotificationDto;
66
use Binarcode\LaravelDeveloper\Models\ExceptionLog;
7+
use Binarcode\LaravelDeveloper\Telescope\TelescopeException;
78
use Illuminate\Support\Collection;
89
use Illuminate\Support\Facades\Notification as NotificationFacade;
910
use Throwable;
@@ -57,6 +58,10 @@ private function send($item)
5758
$dto = DevNotificationDto::makeFromExceptionLog(
5859
tap(ExceptionLog::makeFromException($item), fn (ExceptionLog $log) => $log->save())
5960
);
61+
62+
if (config('developer.interacts_telescope')) {
63+
TelescopeException::recordException($item);
64+
}
6065
} else {
6166
$dto = DevNotificationDto::makeFromException($item);
6267
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace Binarcode\LaravelDeveloper\Telescope;
4+
5+
use Throwable;
6+
7+
class TelescopeException
8+
{
9+
public static function recordException(Throwable $exception, $message = null): void
10+
{
11+
if (!class_exists('Laravel\\Telescope\\Telescope') ||
12+
!class_exists('Laravel\\Telescope\\IncomingExceptionEntry') ||
13+
!class_exists('Laravel\\Telescope\\ExceptionContext')
14+
) {
15+
return;
16+
}
17+
18+
$trace = collect($exception->getTrace())->map(function ($item) {
19+
return Arr::only($item, ['file', 'line']);
20+
})->toArray();
21+
22+
Telescope::recordException(
23+
IncomingExceptionEntry::make($exception, [
24+
'class' => get_class($exception),
25+
'file' => $exception->getFile(),
26+
'line' => $exception->getLine(),
27+
'message' => $message ?? $exception->getMessage(),
28+
'context' => null,
29+
'trace' => $trace,
30+
'line_preview' => ExceptionContext::get($exception),
31+
])
32+
);
33+
}
34+
}

src/helpers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use Binarcode\LaravelDeveloper\Notifications\Slack;
55
use Binarcode\LaravelDeveloper\Profiling\ServerMemory;
66
use Binarcode\LaravelDeveloper\Profiling\ServerTiming;
7+
use Binarcode\LaravelDeveloper\Telescope\TelescopeException;
78

89
if (! function_exists('measure_memory')) {
910
function measure_memory($callable = null, string $key = 'action', string $unit = 'mb')
@@ -54,3 +55,12 @@ function devLog(...$args): DevLog
5455
return DevLog::make(...$args);
5556
}
5657
}
58+
59+
if (! function_exists('telescopeException')) {
60+
function telescopeException(Throwable $exception, $message = null): void
61+
{
62+
if (config('developer.interacts_telescope')) {
63+
TelescopeException::recordException($exception, $message);
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)