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 bbc4e800..7e38303c 100755 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -228,7 +228,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()); } } @@ -266,7 +270,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( @@ -293,7 +300,14 @@ public function generateOtp(Request $request, Otp $otp) try { Mail::to($identifier)->send(new OtpWasGenerated($token->token)); } catch (\Exception $exception) { - Log::debug('Error sending otp email', ['e' => $exception]); + Log::debug( + 'Error sending OTP email', + [ + 'identifier' => $identifier, + 'errorMsg' => $exception + ] + ); + return $this->errorResponse(['message' => 'There was an error processing this request. Please try again.']); } }