mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
fix: enhance exception handling in Elasticsearch connector and improve form validation for credentials as per coderabbitai
This commit is contained in:
parent
a7ad21d7fa
commit
31236f3fc6
2 changed files with 24 additions and 11 deletions
|
|
@ -4,7 +4,11 @@ from collections.abc import AsyncGenerator
|
|||
from typing import Any
|
||||
|
||||
from elasticsearch import AsyncElasticsearch
|
||||
from elasticsearch.exceptions import AuthenticationException, ConnectionError
|
||||
|
||||
try:
|
||||
from elasticsearch.exceptions import AuthenticationException
|
||||
except ImportError:
|
||||
AuthenticationException = Exception
|
||||
|
||||
try:
|
||||
from elastic_transport import (
|
||||
|
|
@ -87,13 +91,9 @@ class ElasticsearchConnector:
|
|||
)
|
||||
return True
|
||||
|
||||
# Updated exception handling for better version compatibility
|
||||
except (ConnectionError, TransportConnectionError, TlsError, ApiError) as e:
|
||||
logger.error(f"Failed to connect to Elasticsearch: {e}")
|
||||
return False
|
||||
except AuthenticationException as e:
|
||||
logger.error(f"Authentication failed for Elasticsearch: {e}")
|
||||
return False
|
||||
except Exception as e:
|
||||
logger.error(f"Unexpected error connecting to Elasticsearch: {e}")
|
||||
return False
|
||||
|
|
|
|||
|
|
@ -64,10 +64,10 @@ const elasticsearchConnectorFormSchema = z
|
|||
.refine(
|
||||
(data) => {
|
||||
if (data.auth_method === "basic") {
|
||||
return data.username && data.password;
|
||||
return Boolean(data.username?.trim() && data.password?.trim());
|
||||
}
|
||||
if (data.auth_method === "api_key") {
|
||||
return data.api_key;
|
||||
return Boolean(data.api_key?.trim());
|
||||
}
|
||||
return true;
|
||||
},
|
||||
|
|
@ -109,10 +109,11 @@ export default function ElasticsearchConnectorPage() {
|
|||
});
|
||||
|
||||
const stringToArray = (str: string): string[] => {
|
||||
return str
|
||||
const items = str
|
||||
.split(",")
|
||||
.map((item) => item.trim())
|
||||
.filter((item) => item.length > 0);
|
||||
return Array.from(new Set(items));
|
||||
};
|
||||
|
||||
// Handle form submission
|
||||
|
|
@ -254,6 +255,8 @@ export default function ElasticsearchConnectorPage() {
|
|||
<FormLabel>Elasticsearch Endpoint URL</FormLabel>
|
||||
<FormControl>
|
||||
<Input
|
||||
type="url"
|
||||
autoComplete="off"
|
||||
placeholder="https://your-cluster.es.region.aws.com:443"
|
||||
{...field}
|
||||
/>
|
||||
|
|
@ -366,7 +369,7 @@ export default function ElasticsearchConnectorPage() {
|
|||
<FormItem>
|
||||
<FormLabel>Username</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="elastic" {...field} />
|
||||
<Input placeholder="elastic" autoComplete="username" {...field} />
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -380,7 +383,12 @@ export default function ElasticsearchConnectorPage() {
|
|||
<FormItem>
|
||||
<FormLabel>Password</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" placeholder="Password" {...field} />
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
autoComplete="current-password"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
|
@ -398,7 +406,12 @@ export default function ElasticsearchConnectorPage() {
|
|||
<FormItem>
|
||||
<FormLabel>API Key</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="password" placeholder="Your API Key Here" {...field} />
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Your API Key Here"
|
||||
autoComplete="off"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormDescription>
|
||||
Enter your Elasticsearch API key (base64 encoded). This will be
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue