Skip to content

Commit

Permalink
chore: improving logging
Browse files Browse the repository at this point in the history
  • Loading branch information
fokosun committed Aug 21, 2023
1 parent 3c2f1c8 commit d74f75b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
27 changes: 16 additions & 11 deletions app/Http/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/',
[
Expand Down Expand Up @@ -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.");
}
Expand All @@ -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(
Expand Down
20 changes: 17 additions & 3 deletions app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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(
Expand All @@ -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.']);
}
}
Expand Down

0 comments on commit d74f75b

Please sign in to comment.