mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 04:07:32 -05:00 
			
		
		
		
	Merge pull request #8169 from turbo124/v5-develop
Improve sentry logging in selfhost + hosted
This commit is contained in:
		
						commit
						4fb80f98dd
					
				@ -36,6 +36,7 @@ use Symfony\Component\Console\Exception\CommandNotFoundException;
 | 
			
		||||
use Symfony\Component\Debug\Exception\FatalThrowableError;
 | 
			
		||||
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
 | 
			
		||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 | 
			
		||||
use League\Flysystem\UnableToCreateDirectory;
 | 
			
		||||
use Throwable;
 | 
			
		||||
 | 
			
		||||
class Handler extends ExceptionHandler
 | 
			
		||||
@ -54,6 +55,30 @@ class Handler extends ExceptionHandler
 | 
			
		||||
        NotFoundHttpException::class,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    protected $selfHostDontReport = [
 | 
			
		||||
        FilePermissionsFailure::class,
 | 
			
		||||
        PDOException::class,
 | 
			
		||||
        MaxAttemptsExceededException::class,
 | 
			
		||||
        CommandNotFoundException::class,
 | 
			
		||||
        ValidationException::class,
 | 
			
		||||
        ModelNotFoundException::class,
 | 
			
		||||
        NotFoundHttpException::class,
 | 
			
		||||
        UnableToCreateDirectory::class,
 | 
			
		||||
        GuzzleHttp\Exception\ConnectException::class,
 | 
			
		||||
        Symfony\Component\Process\Exception\RuntimeException::class,
 | 
			
		||||
        InvalidArgumentException::class,
 | 
			
		||||
        RuntimeException::class,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    protected $hostedDontReport = [
 | 
			
		||||
        PDOException::class,
 | 
			
		||||
        MaxAttemptsExceededException::class,
 | 
			
		||||
        CommandNotFoundException::class,
 | 
			
		||||
        ValidationException::class,
 | 
			
		||||
        ModelNotFoundException::class,
 | 
			
		||||
        NotFoundHttpException::class,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * A list of the inputs that are never flashed for validation exceptions.
 | 
			
		||||
     *
 | 
			
		||||
@ -100,11 +125,11 @@ class Handler extends ExceptionHandler
 | 
			
		||||
                ]);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            if ($this->validException($exception)) {
 | 
			
		||||
            if ($this->validException($exception) && $this->sentryShouldReport($exception)) {
 | 
			
		||||
                Integration::captureUnhandledException($exception);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
        } elseif (app()->bound('sentry') && $this->shouldReport($exception)) {
 | 
			
		||||
        } elseif (app()->bound('sentry')) {
 | 
			
		||||
            Integration::configureScope(function (Scope $scope): void {
 | 
			
		||||
                if (auth()->guard('contact') && auth()->guard('contact')->user() && auth()->guard('contact')->user()->company->account->report_errors) {
 | 
			
		||||
                    $scope->setUser([
 | 
			
		||||
@ -121,7 +146,7 @@ class Handler extends ExceptionHandler
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            if ($this->validException($exception)) {
 | 
			
		||||
            if ($this->validException($exception) && $this->sentryShouldReport($exception)) {
 | 
			
		||||
                Integration::captureUnhandledException($exception);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@ -158,6 +183,23 @@ class Handler extends ExceptionHandler
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Determine if the exception is in the "do not report" list.
 | 
			
		||||
     *
 | 
			
		||||
     * @param  \Throwable  $e
 | 
			
		||||
     * @return bool
 | 
			
		||||
     */
 | 
			
		||||
    protected function sentryShouldReport(Throwable $e)
 | 
			
		||||
    {
 | 
			
		||||
        if(Ninja::isHosted())
 | 
			
		||||
            $dontReport = array_merge($this->hostedDontReport, $this->internalDontReport);
 | 
			
		||||
        else
 | 
			
		||||
            $dontReport = array_merge($this->selfHostDontReport, $this->internalDontReport);
 | 
			
		||||
 | 
			
		||||
        return is_null(Arr::first($dontReport, fn ($type) => $e instanceof $type));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Render an exception into an HTTP response.
 | 
			
		||||
     *
 | 
			
		||||
@ -194,7 +236,6 @@ class Handler extends ExceptionHandler
 | 
			
		||||
        } elseif ($exception instanceof MethodNotAllowedHttpException && $request->expectsJson()) {
 | 
			
		||||
            return response()->json(['message'=>'Method not supported for this route'], 404);
 | 
			
		||||
        } elseif ($exception instanceof ValidationException && $request->expectsJson()) {
 | 
			
		||||
            // nlog($exception->validator->getMessageBag());
 | 
			
		||||
            return response()->json(['message' => 'The given data was invalid.', 'errors' => $exception->validator->getMessageBag()], 422);
 | 
			
		||||
        } elseif ($exception instanceof RelationNotFoundException && $request->expectsJson()) {
 | 
			
		||||
            return response()->json(['message' => "Relation `{$exception->relation}` is not a valid include."], 400);
 | 
			
		||||
 | 
			
		||||
@ -40,7 +40,8 @@ class SchedulerService
 | 
			
		||||
    private function client_statement()
 | 
			
		||||
    {   
 | 
			
		||||
        $query = Client::query()
 | 
			
		||||
                        ->where('company_id', $this->scheduler->company_id);
 | 
			
		||||
                        ->where('company_id', $this->scheduler->company_id)
 | 
			
		||||
                        ->where('is_deleted',0);
 | 
			
		||||
 | 
			
		||||
        //Email only the selected clients
 | 
			
		||||
        if(count($this->scheduler->parameters['clients']) >= 1)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user