Skip to content

Commit cfd16c8

Browse files
committed
#2922 - Add GLOBAL_ERROR_HANDLER event emission to load and analyse functions
1 parent 067cfa0 commit cfd16c8

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

packages/ketcher-react/src/script/ui/state/server/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
* limitations under the License.
1515
***************************************************************************/
1616

17-
import { ChemicalMimeType, KetcherLogger, KetSerializer } from 'ketcher-core';
17+
import {
18+
ChemicalMimeType,
19+
KetcherLogger,
20+
KetSerializer,
21+
ketcherProvider,
22+
} from 'ketcher-core';
1823
import { appUpdate, setStruct } from '../options';
1924
import { omit, without } from 'lodash/fp';
2025

2126
import { checkErrors } from '../modal/form';
2227
import { indigoVerification } from '../request';
2328
import { load } from '../shared';
29+
import { GLOBAL_ERROR_HANDLER } from 'src/constants';
2430

2531
export function checkServer() {
2632
return (dispatch, getState) => {
@@ -112,6 +118,7 @@ export function analyse() {
112118
});
113119
const { editor, server, options } = getState();
114120
const serverSettings = options.getServerSettings();
121+
const ketcher = ketcherProvider.getKetcher();
115122
serverSettings.data = {
116123
properties: [
117124
'molecular-weight',
@@ -132,7 +139,9 @@ export function analyse() {
132139
.catch((e) => {
133140
KetcherLogger.error('index.js::analyse', e);
134141
editor.errorHandler(e);
135-
throw e;
142+
if (ketcher && ketcher.eventBus) {
143+
ketcher.eventBus.emit(GLOBAL_ERROR_HANDLER, e);
144+
}
136145
});
137146
};
138147
}

packages/ketcher-react/src/script/ui/state/shared.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@ import {
2626
Editor,
2727
KetcherLogger,
2828
SettingsManager,
29+
ketcherProvider,
2930
} from 'ketcher-core';
3031

3132
import { supportedSGroupTypes } from './constants';
3233
import { setAnalyzingFile } from './request';
3334
import tools from '../action/tools';
35+
import { GLOBAL_ERROR_HANDLER } from 'src/constants';
3436

3537
export function onAction(action) {
3638
if (action && action.dialog) {
@@ -101,6 +103,7 @@ export function load(struct: Struct, options?) {
101103
const editor = state.editor as Editor;
102104
const server = state.server;
103105
const errorHandler = editor.errorHandler;
106+
const ketcher = ketcherProvider.getKetcher();
104107
options = options || {};
105108
let { isPaste, ...otherOptions } = options;
106109
otherOptions = {
@@ -184,7 +187,9 @@ export function load(struct: Struct, options?) {
184187
KetcherLogger.error('shared.ts::load', e);
185188
dispatch(setAnalyzingFile(false));
186189
e && errorHandler && errorHandler(e.message);
187-
throw e;
190+
if (ketcher && ketcher.eventBus) {
191+
ketcher.eventBus.emit(GLOBAL_ERROR_HANDLER, e.message);
192+
}
188193
} finally {
189194
notifyRequestCompleted();
190195
}

packages/ketcher-react/src/script/ui/views/modal/components/document/Open/Open.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import Recognize from '../../process/Recognize/Recognize';
2222
import { fileOpener } from '../../../../../utils/';
2323
import { DialogActionButton } from './components/DialogActionButton';
2424
import { ViewSwitcher } from './components/ViewSwitcher';
25-
import { getFormatMimeTypeByFileName, ketcherProvider } from 'ketcher-core';
26-
import { GLOBAL_ERROR_HANDLER } from 'src/constants';
25+
import { getFormatMimeTypeByFileName } from 'ketcher-core';
2726
import { useDispatch } from 'react-redux';
2827
import { load } from 'src/script/ui/state/shared';
2928

@@ -117,17 +116,10 @@ const Open: FC<Props> = (props) => {
117116
// @TODO after Recognize is refactored this will not be necessary
118117
// currently not destructuring onOk with other props so we can pass it with ...rest to Recognize below
119118

120-
const ketcher = ketcherProvider.getKetcher();
121119
const onOk = async (res) => {
122-
try {
123-
await dispatch(
124-
load(res.structStr, { badHeaderRecover: true, fragment: res.fragment }),
125-
);
126-
} catch (error: any) {
127-
if (ketcher && ketcher.eventBus) {
128-
ketcher.eventBus.emit(GLOBAL_ERROR_HANDLER, error.message);
129-
}
130-
}
120+
await dispatch(
121+
load(res.structStr, { badHeaderRecover: true, fragment: res.fragment }),
122+
);
131123
};
132124

133125
const copyHandler = () => {

packages/ketcher-react/src/script/ui/views/modal/components/process/Analyse/Analyse.jsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,7 @@ const mapStateToProps = (state) => ({
153153
});
154154

155155
const mapDispatchToProps = (dispatch) => ({
156-
onAnalyse: () => {
157-
return dispatch(analyse()).catch((error) => {
158-
const ketcher = ketcherProvider.getKetcher();
159-
if (ketcher && ketcher.eventBus) {
160-
ketcher.eventBus.emit(GLOBAL_ERROR_HANDLER, error);
161-
}
162-
});
163-
},
156+
onAnalyse: () => dispatch(analyse()),
164157
onChangeRound: (roundName, val) => dispatch(changeRound(roundName, val)),
165158
});
166159

0 commit comments

Comments
 (0)