diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index c5e48375..ab59a4ef 100755 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -5,7 +5,6 @@ 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; @@ -13,13 +12,6 @@ class Handler extends ExceptionHandler { - public function register() - { - $this->reportable(function (Throwable $e) { - Integration::captureUnhandledException($e); - }); - } - /** * Report or log an exception. * @@ -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); diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 113db416..f8ca3473 100755 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -17,6 +17,7 @@ use Illuminate\Http\Response; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; +use Tymon\JWTAuth\Exceptions\JWTException; /** * Class AuthController @@ -134,14 +135,14 @@ public function loginViaMagicLink(Request $request, LocationService $locationSer */ public function tikTokHandleCallback(Request $request, Client $client, UserService $service) { - try { - $code = $request->get('code'); - $errCode = $request->get('errCode'); + $code = $request->get('code'); + $errCode = $request->get('errCode'); - if ($errCode === self::TIKTOK_CANCELLATION_CODE) { - return redirect('https://web.cookbookshq.com/#/signin'); - } + if ($errCode === self::TIKTOK_CANCELLATION_CODE) { + return redirect('https://web.cookbookshq.com/#/signin'); + } + try { $response = $client->request('POST', 'https://open-api.tiktok.com/oauth/access_token/', [ @@ -242,9 +243,13 @@ public function tikTokHandleCallback(Request $request, Client $client, UserServi return redirect('https://web.cookbookshq.com/#/errors/?m=Hey, it looks like your tiktok account is Private. Please login using a public account.'); } } catch (\Exception $e) { - Log::debug('There was an error', [ - 'error' => $e->getMessage(), - ]); + Log::debug( + 'Tiktok Login error', + [ + 'errorCode' => $errCode, + 'errorMsg' => $e->getMessage() + ] + ); return redirect("https://web.cookbookshq.com/#/errors/?m=We are experiencing some technical difficulty logging you in with TikTok, please try again."); } @@ -253,12 +258,12 @@ public function tikTokHandleCallback(Request $request, Client $client, UserServi /** * @param Request $request * @return \Illuminate\Http\JsonResponse - * @throws \Tymon\JWTAuth\Exceptions\JWTException + * @throws JWTException */ public function validateToken(Request $request) { if (!$request->bearerToken() || !Auth::check()) { - throw new \Tymon\JWTAuth\Exceptions\JWTException('Expired or Tnvalid token.'); + throw new JWTException('Expired or Tnvalid token.'); } return response()->json( diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 36e30362..20ff0a71 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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; @@ -24,6 +25,7 @@ use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; use Tymon\JWTAuth\Facades\JWTAuth; +use Ichtrojan\Otp\Models\Otp as OtpModel; /** * Class UserController @@ -227,7 +229,11 @@ public function addFeedback(Request $request) ]) ]); } catch (ApiException $exception){ - Log::debug('error creating user feedback', ['exception' => $exception]); + Log::debug( + 'error creating user feedback', + ['exception' => $exception] + ); + return response()->json(['error', 'There was an error processing this request. Please try again later.'], $exception->getCode()); } } @@ -265,7 +271,10 @@ public function listVideos(HttpRequestRunner $requestRunner) ] ]); } catch (\Exception $exception) { - Log::debug("Error listing tiktok user videos", ['exception' => $exception]); + Log::debug( + "Error listing tiktok user videos", + ['exception' => $exception] + ); return [ 'data' => array_merge( @@ -290,9 +299,16 @@ 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', + [ + 'identifier' => $identifier, + 'errorMsg' => $exception->getMessage() + ] + ); + return $this->errorResponse(['message' => 'There was an error processing this request. Please try again.']); } } diff --git a/app/Listeners/GetTikTokUserVideos.php b/app/Listeners/GetTikTokUserVideos.php index cf4c0a7d..f991ae0c 100644 --- a/app/Listeners/GetTikTokUserVideos.php +++ b/app/Listeners/GetTikTokUserVideos.php @@ -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 { @@ -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]); } } } diff --git a/config/logging.php b/config/logging.php index 31d4bae3..8518f2a5 100755 --- a/config/logging.php +++ b/config/logging.php @@ -19,7 +19,7 @@ | */ - 'default' => env('LOG_CHANNEL', 'stack'), + 'default' => env('LOG_CHANNEL', 'sentry'), /* |-------------------------------------------------------------------------- @@ -101,6 +101,11 @@ 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], + + 'sentry' => [ + 'driver' => 'sentry', + 'channels' => ['single', 'sentry'], + ], ], ]; diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..a1493f2f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "api", + "lockfileVersion": 3, + "requires": true, + "packages": {} +}