Repository: appwrite/appwrite
File: app/controllers/general.php (PHP)

Code before:
                $error = new AppwriteException(AppwriteException::GENERAL_QUERY_INVALID, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\Structure':
                $error = new AppwriteException(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\Duplicate':
                $error = new AppwriteException(AppwriteException::DOCUMENT_ALREADY_EXISTS);
                break;
            case 'Utopia\Database\Exception\Restricted':
                $error = new AppwriteException(AppwriteException::DOCUMENT_DELETE_RESTRICTED);
                break;
            case 'Utopia\Database\Exception\Authorization':
                $error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED);
                break;
            case 'Utopia\Database\Exception\Relationship':
                $error = new AppwriteException(AppwriteException::RELATIONSHIP_VALUE_INVALID, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\NotFound':
                $error = new AppwriteException(AppwriteException::COLLECTION_NOT_FOUND, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\Dependency':
                $error = new AppwriteException(AppwriteException::INDEX_DEPENDENCY, null, previous: $error);
                break;
            case 'Utopia\Database\Exception\Index':
                $error = new AppwriteException(AppwriteException::INDEX_INVALID, $error->getMessage(), previous: $error);
                break;
        }

        $code = $error->getCode();
        $message = $error->getMessage();

        if ($error instanceof AppwriteException) {
            $publish = $error->isPublishable();
        } else {
            $publish = $error->getCode() === 0 || $error->getCode() >= 500;
        }

        if ($error->getCode() >= 400 && $error->getCode() < 500) {
            // Register error logger
            $providerName = System::getEnv('_APP_EXPERIMENT_LOGGING_PROVIDER', '');
            $providerConfig = System::getEnv('_APP_EXPERIMENT_LOGGING_CONFIG', '');

            try {
                $loggingProvider = new DSN($providerConfig ?? '');
                $providerName = $loggingProvider->getScheme();

                if (!empty($providerName) && $providerName === 'sentry') {
                    $key = $loggingProvider->getPassword();
                    $projectId = $loggingProvider->getUser() ?? '';
                    $host = 'https://' . $loggingProvider->getHost();


Review comment (suggestion):
We want to move away from catching expected exceptions in the general handler, let's add this only where needed in the databases controller/worker

Code after:
                $error = new AppwriteException(AppwriteException::GENERAL_QUERY_INVALID, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\Structure':
                $error = new AppwriteException(AppwriteException::DOCUMENT_INVALID_STRUCTURE, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\Duplicate':
                $error = new AppwriteException(AppwriteException::DOCUMENT_ALREADY_EXISTS);
                break;
            case 'Utopia\Database\Exception\Restricted':
                $error = new AppwriteException(AppwriteException::DOCUMENT_DELETE_RESTRICTED);
                break;
            case 'Utopia\Database\Exception\Authorization':
                $error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED);
                break;
            case 'Utopia\Database\Exception\Relationship':
                $error = new AppwriteException(AppwriteException::RELATIONSHIP_VALUE_INVALID, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\NotFound':
                $error = new AppwriteException(AppwriteException::COLLECTION_NOT_FOUND, $error->getMessage(), previous: $error);
                break;
            case 'Utopia\Database\Exception\Dependency':
                $error = new AppwriteException(AppwriteException::INDEX_DEPENDENCY, null, previous: $error);
                break;
        }

        $code = $error->getCode();
        $message = $error->getMessage();

        if ($error instanceof AppwriteException) {
            $publish = $error->isPublishable();
        } else {
            $publish = $error->getCode() === 0 || $error->getCode() >= 500;
        }

        if ($error->getCode() >= 400 && $error->getCode() < 500) {
            // Register error logger
            $providerName = System::getEnv('_APP_EXPERIMENT_LOGGING_PROVIDER', '');
            $providerConfig = System::getEnv('_APP_EXPERIMENT_LOGGING_CONFIG', '');

            try {
                $loggingProvider = new DSN($providerConfig ?? '');
                $providerName = $loggingProvider->getScheme();

                if (!empty($providerName) && $providerName === 'sentry') {
                    $key = $loggingProvider->getPassword();
                    $projectId = $loggingProvider->getUser() ?? '';
                    $host = 'https://' . $loggingProvider->getHost();

                    $adapter = new Sentry($projectId, $key, $host);
                    $logger = new Logger($adapter);
                    $logger->setSample(0.01);