Skip to content

Commit

Permalink
Merge pull request #277 from mycookbook/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
fokosun authored Aug 21, 2023
2 parents faf3376 + 2fa7582 commit 710cbd5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 28 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
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
24 changes: 20 additions & 4 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 All @@ -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
Expand Down Expand Up @@ -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());
}
}
Expand Down Expand Up @@ -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(
Expand All @@ -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.']);
}
}
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 710cbd5

Please sign in to comment.