Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/ErrorBoundary/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export function ErrorBoundaryFallback({error}: ErrorBoundaryFallbackProps) {
const [diagnosticsData, setDiagnosticsData] = React.useState<DiagnosticsData | undefined>();

React.useEffect(() => {
collectDiagnosticsData(error).then((data) => {
const database = new URLSearchParams(window.location.search).get('database') ?? undefined;
Comment thread
Raubzeug marked this conversation as resolved.

collectDiagnosticsData(error, database).then((data) => {
setDiagnosticsData(data);
});
}, [error]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type {YdbEmbeddedAPI} from '../../../services/api';
import {collectDiagnosticsData} from '../utils';

describe('collectDiagnosticsData', () => {
const originalApi = window.api;

afterEach(() => {
window.api = originalApi;
});

test('passes database to the backend version request', async () => {
const getNodeInfo = jest.fn().mockResolvedValue({
SystemStateInfo: [{Version: 'test-backend-version'}],
});
window.api = {
viewer: {
getNodeInfo,
},
} as unknown as YdbEmbeddedAPI;

const result = await collectDiagnosticsData(new Error('Test error'), '/Root/test-database');

expect(getNodeInfo).toHaveBeenCalledWith(
{
nodeId: '.',
database: '/Root/test-database',
},
{timeout: 1000},
);
expect(result.backendVersion).toBe('test-backend-version');
});
});
8 changes: 4 additions & 4 deletions src/components/ErrorBoundary/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {prepareErrorMessage} from '../../utils/prepareErrorMessage';

import packageJson from '../../../package.json';

export async function collectDiagnosticsData(error: Error) {
return await getBackendVersion().then((backendVersion) => {
export async function collectDiagnosticsData(error: Error, database?: string) {
return await getBackendVersion(database).then((backendVersion) => {
return {
location: window.location.href,
userAgent: navigator.userAgent,
Expand All @@ -19,12 +19,12 @@ export async function collectDiagnosticsData(error: Error) {

export type DiagnosticsData = Awaited<ReturnType<typeof collectDiagnosticsData>>;

async function getBackendVersion() {
async function getBackendVersion(database?: string) {
try {
// node_id=. returns data about node that fullfills request
// normally this request should be fast (200-300ms with good connection)
// timeout=1000 in order not to wait too much in case everything is broken
const data = await window.api.viewer.getNodeInfo({nodeId: '.'}, {timeout: 1000});
const data = await window.api.viewer.getNodeInfo({nodeId: '.', database}, {timeout: 1000});
return data?.SystemStateInfo?.[0]?.Version;
} catch (error) {
return {error: prepareErrorMessage(error)};
Expand Down
Loading