Skip to content

Commit

Permalink
Setup logging with sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Aug 21, 2023
1 parent b0e6cf9 commit 3c2f1c8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
10 changes: 1 addition & 9 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,13 @@
namespace App\Exceptions;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Sentry\Laravel\Integration;
use Illuminate\Http\Response;
use Illuminate\Validation\UnauthorizedException;
use Illuminate\Validation\ValidationException;
use Throwable;

class Handler extends ExceptionHandler
{
public function register()
{
$this->reportable(function (Throwable $e) {
Integration::captureUnhandledException($e);
});
}

/**
* Report or log an exception.
*
Expand Down Expand Up @@ -67,7 +59,7 @@ public function render($request, Throwable $throwable)
}

if ($throwable instanceof TikTokException) {
return response()->json( ['error' => $throwable->getMessage()]);
return response()->json(['error' => $throwable->getMessage()]);
}

return parent::render($request, $throwable);
Expand Down
5 changes: 3 additions & 2 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Requests\UserStoreRequest;
use App\Http\Requests\UserUpdateRequest;
use App\Jobs\TriggerEmailVerificationProcess;
use App\Mail\OtpWasGenerated;
use App\Models\EmailVerification;
use App\Models\Following;
use App\Models\User;
Expand Down Expand Up @@ -290,9 +291,9 @@ public function generateOtp(Request $request, Otp $otp)
);

try {
Mail::to($identifier)->send(new \App\Mail\OtpWasGenerated($token->token));
Mail::to($identifier)->send(new OtpWasGenerated($token->token));
} catch (\Exception $exception) {
Log::debug('Error sending email', ['e' => $exception]);
Log::debug('Error sending otp email', ['e' => $exception]);
return $this->errorResponse(['message' => 'There was an error processing this request. Please try again.']);
}
}
Expand Down
5 changes: 2 additions & 3 deletions app/Listeners/GetTikTokUserVideos.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace App\Listeners;

use App\Exceptions\TikTokException;
use GuzzleHttp\Client;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class GetTikTokUserVideos
{
Expand Down Expand Up @@ -61,8 +61,7 @@ public function handle(object $event): void
}

} catch(\Exception $exception) {
dd($exception->getMessage());
// throw new TikTokException($exception->getMessage(), $context);
Log::debug('Error listing TikTok videos', ['e' => $exception]);
}
}
}
7 changes: 6 additions & 1 deletion config/logging.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
|
*/

'default' => env('LOG_CHANNEL', 'stack'),
'default' => env('LOG_CHANNEL', 'sentry'),

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -101,6 +101,11 @@
'emergency' => [
'path' => storage_path('logs/laravel.log'),
],

'sentry' => [
'driver' => 'sentry',
'channels' => ['single', 'sentry'],
],
],

];
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c2f1c8

Please sign in to comment.