mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat(core): GQLErrorCatcher helper class
This commit is contained in:
@@ -33,8 +33,7 @@ export class ServerService {
|
||||
this.settings.clear();
|
||||
parseJSONFlat(
|
||||
serverConfig.productConfiguration,
|
||||
this.settings.setSelfValue.bind(this.settings),
|
||||
undefined
|
||||
this.settings.setSelfValue.bind(this.settings)
|
||||
);
|
||||
}
|
||||
return serverConfig;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* cloudbeaver - Cloud Database Manager
|
||||
* Copyright (C) 2020 DBeaver Corp and others
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0.
|
||||
* you may not use this file except in compliance with the License.
|
||||
*/
|
||||
|
||||
import { observable, action } from 'mobx';
|
||||
|
||||
import { GQLError } from './GQLError';
|
||||
|
||||
export class GQLErrorCatcher {
|
||||
@observable hasDetails = false
|
||||
@observable responseMessage: string | null = null
|
||||
@observable exception: GQLError | null = null;
|
||||
|
||||
@action catch(exception: any): boolean {
|
||||
if (exception instanceof GQLError) {
|
||||
this.responseMessage = exception.errorText;
|
||||
this.hasDetails = exception.hasDetails();
|
||||
this.exception = exception;
|
||||
return true;
|
||||
}
|
||||
this.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
@action clear() {
|
||||
this.hasDetails = false;
|
||||
this.responseMessage = null;
|
||||
this.exception = null;
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,4 @@ export * from './GQLError';
|
||||
export * from './ServerInternalError';
|
||||
export * from './CachedResource';
|
||||
export * from './EServerErrorCode';
|
||||
export * from './GQLErrorCatcher';
|
||||
|
||||
+3
-4
@@ -24,7 +24,6 @@ import { ConnectionFormDialogController } from './ConnectionFormDialogController
|
||||
import { ConnectionFormDialogFooter } from './ConnectionFormDialogFooter';
|
||||
import { DriverProperties } from './DriverProperties/DriverProperties';
|
||||
|
||||
|
||||
const styles = composes(
|
||||
css`
|
||||
BaseTab {
|
||||
@@ -149,10 +148,10 @@ export const ConnectionFormDialog = observer(
|
||||
/>
|
||||
</BaseTabPanel>
|
||||
</SubmittingForm>
|
||||
{controller.responseMessage && (
|
||||
{controller.error.responseMessage && (
|
||||
<ErrorMessage
|
||||
text={controller.responseMessage}
|
||||
hasDetails={controller.hasDetails}
|
||||
text={controller.error.responseMessage}
|
||||
hasDetails={controller.error.hasDetails}
|
||||
onShowDetails={controller.onShowDetails}
|
||||
/>
|
||||
)}
|
||||
|
||||
+7
-20
@@ -12,7 +12,7 @@ import { DBDriver, ErrorDetailsDialog } from '@dbeaver/core/app';
|
||||
import { injectable, IInitializableController, IDestructibleController } from '@dbeaver/core/di';
|
||||
import { CommonDialogService } from '@dbeaver/core/dialogs';
|
||||
import { NotificationService } from '@dbeaver/core/eventsLog';
|
||||
import { ConnectionConfig, GQLError } from '@dbeaver/core/sdk';
|
||||
import { ConnectionConfig, GQLErrorCatcher } from '@dbeaver/core/sdk';
|
||||
|
||||
import { CustomConnectionService } from '../../CustomConnectionService';
|
||||
|
||||
@@ -39,10 +39,7 @@ implements IInitializableController, IDestructibleController {
|
||||
url: '',
|
||||
properties: {},
|
||||
}
|
||||
@observable hasDetails = false
|
||||
@observable responseMessage: string | null = null
|
||||
|
||||
private exception: GQLError | null = null;
|
||||
readonly error = new GQLErrorCatcher();
|
||||
private onClose!: () => void
|
||||
private isDistructed = false;
|
||||
|
||||
@@ -70,7 +67,7 @@ implements IInitializableController, IDestructibleController {
|
||||
|
||||
onTestConnection = async () => {
|
||||
this.isConnecting = true;
|
||||
this.clearError();
|
||||
this.error.clear();
|
||||
try {
|
||||
await this.customConnectionService.testConnectionAsync(this.getConnectionConfig());
|
||||
|
||||
@@ -84,7 +81,7 @@ implements IInitializableController, IDestructibleController {
|
||||
|
||||
onCreateConnection = async () => {
|
||||
this.isConnecting = true;
|
||||
this.clearError();
|
||||
this.error.clear();
|
||||
try {
|
||||
const connection = await this.customConnectionService.createConnectionAsync(this.getConnectionConfig());
|
||||
|
||||
@@ -98,8 +95,8 @@ implements IInitializableController, IDestructibleController {
|
||||
}
|
||||
|
||||
onShowDetails = () => {
|
||||
if (this.exception) {
|
||||
this.commonDialogService.open(ErrorDetailsDialog, this.exception);
|
||||
if (this.error.exception) {
|
||||
this.commonDialogService.open(ErrorDetailsDialog, this.error.exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,12 +141,6 @@ implements IInitializableController, IDestructibleController {
|
||||
this.config.properties = {};
|
||||
}
|
||||
|
||||
private clearError() {
|
||||
this.responseMessage = null;
|
||||
this.hasDetails = false;
|
||||
this.exception = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates connection name based on connection url
|
||||
* @param defaultName default connection name if url parsing failed
|
||||
@@ -175,11 +166,7 @@ implements IInitializableController, IDestructibleController {
|
||||
}
|
||||
|
||||
private showError(exception: Error, message: string) {
|
||||
if (exception instanceof GQLError && !this.isDistructed) {
|
||||
this.responseMessage = exception.errorText;
|
||||
this.hasDetails = exception.hasDetails();
|
||||
this.exception = exception;
|
||||
} else {
|
||||
if (!this.error.catch(exception) || this.isDistructed) {
|
||||
this.notificationService.logException(exception, message);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,7 +9,7 @@
|
||||
import { observer } from 'mobx-react';
|
||||
|
||||
import { useController } from '@dbeaver/core/di';
|
||||
import { DialogComponent, DialogComponentProps } from '@dbeaver/core/dialogs';
|
||||
import { DialogComponent } from '@dbeaver/core/dialogs';
|
||||
import { useTranslate } from '@dbeaver/core/localization';
|
||||
|
||||
import { ConnectionFormDialog } from './ConnectionFormDialog/ConnectionFormDialog';
|
||||
@@ -17,7 +17,7 @@ import { CustomConnectionController, ConnectionStep } from './CustomConnectionCo
|
||||
import { DriverSelectorDialog } from './DriverSelectorDialog/DriverSelectorDialog';
|
||||
|
||||
export const CustomConnectionDialog: DialogComponent<null, null> = observer(
|
||||
function CustomConnectionDialog(props: DialogComponentProps<null, null>) {
|
||||
function CustomConnectionDialog(props) {
|
||||
const controller = useController(CustomConnectionController);
|
||||
let title = useTranslate('basicConnection_connectionDialog_newConnection');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user