Separated laravel app to its own folder (#540)
This commit is contained in:
19
api/app/Exceptions/EmailTakenException.php
Normal file
19
api/app/Exceptions/EmailTakenException.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class EmailTakenException extends Exception
|
||||
{
|
||||
/**
|
||||
* Render the exception as an HTTP response.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function render($request)
|
||||
{
|
||||
return response()->view('oauth.emailTaken', [], 400);
|
||||
}
|
||||
}
|
||||
84
api/app/Exceptions/Handler.php
Normal file
84
api/app/Exceptions/Handler.php
Normal file
@@ -0,0 +1,84 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
/**
|
||||
* A list of the exception types that are not reported.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the exception types that are not reported to Sentry.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sentryDontReport = [
|
||||
//
|
||||
];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontFlash = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
|
||||
/**
|
||||
* Convert an authentication exception into a response.
|
||||
*/
|
||||
protected function unauthenticated($request, AuthenticationException $exception)
|
||||
{
|
||||
return response()->json(['message' => $exception->getMessage()], 401);
|
||||
}
|
||||
|
||||
public function report(Throwable $exception)
|
||||
{
|
||||
if ($this->shouldReport($exception)) {
|
||||
if (app()->bound('sentry') && $this->sentryShouldReport($exception)) {
|
||||
app('sentry')->captureException($exception);
|
||||
Log::debug('Un-handled Exception: '.$exception->getMessage(), [
|
||||
'exception' => $exception,
|
||||
'file' => $exception->getFile(),
|
||||
'line' => $exception->getLine(),
|
||||
'trace' => $exception->getTrace(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
parent::report($exception);
|
||||
}
|
||||
|
||||
public function render($request, Throwable $e)
|
||||
{
|
||||
if ($this->shouldReport($e) && ! in_array(\App::environment(), ['testing']) && config('logging.channels.slack.enabled')) {
|
||||
Log::channel('slack')->error($e);
|
||||
}
|
||||
|
||||
return parent::render($request, $e);
|
||||
}
|
||||
|
||||
private function sentryShouldReport(Throwable $e)
|
||||
{
|
||||
foreach ($this->sentryDontReport as $exceptionType) {
|
||||
if ($e instanceof $exceptionType) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
22
api/app/Exceptions/VerifyEmailException.php
Normal file
22
api/app/Exceptions/VerifyEmailException.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions;
|
||||
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class VerifyEmailException extends ValidationException
|
||||
{
|
||||
/**
|
||||
* @param \App\User $user
|
||||
* @return static
|
||||
*/
|
||||
public static function forUser($user)
|
||||
{
|
||||
return static::withMessages([
|
||||
'email' => [__('You must :linkOpen verify :linkClose your email first.', [
|
||||
'linkOpen' => '<a href="/email/resend?email='.urlencode($user->email).'">',
|
||||
'linkClose' => '</a>',
|
||||
])],
|
||||
]);
|
||||
}
|
||||
}
|
||||
26
api/app/Exceptions/Workspaces/WorkspaceAlreadyExisting.php
Normal file
26
api/app/Exceptions/Workspaces/WorkspaceAlreadyExisting.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions\Workspaces;
|
||||
|
||||
use App\Models\Workspace;
|
||||
use Exception;
|
||||
|
||||
class WorkspaceAlreadyExisting extends Exception
|
||||
{
|
||||
public function __construct(public Workspace $workspace)
|
||||
{
|
||||
}
|
||||
|
||||
public function getErrorMessage()
|
||||
{
|
||||
$owner = $this->workspace->users()->first();
|
||||
if (! $owner) {
|
||||
return 'A user already connected that workspace to another NotionForms account. You or the current workspace
|
||||
owner must have a NotionForms Enterprise subscription for you to add this Notion workspace. Please upgrade
|
||||
with an Enterprise subscription, or contact us to get help.';
|
||||
}
|
||||
|
||||
return '"'.$owner->name.'" already connected that workspace to his NotionForms account. In order to collaborate,
|
||||
one of you must have a NotionForms Enterprise subscription. Please upgrade or contact us to get help.';
|
||||
}
|
||||
}
|
||||
10
api/app/Exceptions/Workspaces/WorkspaceLimit.php
Normal file
10
api/app/Exceptions/Workspaces/WorkspaceLimit.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exceptions\Workspaces;
|
||||
|
||||
use Exception;
|
||||
|
||||
class WorkspaceLimit extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
Reference in New Issue
Block a user