@@ -26,7 +26,8 @@ import EventBusMixin from './EventBusMixin';
26
26
import WorkPanelMixin from ' ./WorkPanelMixin' ;
27
27
import SyncButton from ' ./SyncButton.vue' ;
28
28
import Utils from ' ../utils.js' ;
29
- import { AbortController , Job } from ' @openeo/js-client' ;
29
+ import { Job } from ' @openeo/js-client' ;
30
+ import { cancellableRequest , showCancellableRequestError , CancellableRequestError } from ' ./cancellableRequest' ;
30
31
31
32
const WorkPanelMixinInstance = WorkPanelMixin (' jobs' , ' batch job' , ' batch jobs' );
32
33
@@ -39,8 +40,7 @@ export default {
39
40
data () {
40
41
return {
41
42
watchers: {},
42
- jobUpdater: null ,
43
- runId: 0
43
+ jobUpdater: null
44
44
};
45
45
},
46
46
mounted () {
@@ -145,48 +145,20 @@ export default {
145
145
await this .queueJob (job);
146
146
},
147
147
async executeProcess () {
148
- let abortController = new AbortController ();
149
- let snotifyConfig = {
150
- timeout: 0 ,
151
- type: ' async' ,
152
- buttons: [{
153
- text: ' Cancel' ,
154
- action : toast => {
155
- abortController .abort ();
156
- this .$snotify .remove (toast .id , true );
157
- }
158
- }]
148
+ const callback = async (abortController ) => {
149
+ const result = await this .connection .computeResult (this .process , null , null , abortController);
150
+ this .broadcast (' viewSyncResult' , result);
159
151
};
160
- let toast;
161
152
try {
162
- this .runId ++ ;
163
- let message = " A process is currently executed synchronously..." ;
164
- let title = ` Run #${ this .runId } ` ;
165
- let endlessPromise = () => new Promise (() => {}); // Pass a promise to snotify that never resolves as we manually close the toast
166
- toast = this .$snotify .async (message, title, endlessPromise, snotifyConfig);
167
- let result = await this .connection .computeResult (this .process , null , null , abortController);
168
- this .broadcast (' viewSyncResult' , result);
169
- } catch (error) {
170
- if (axios .isCancel (error)) {
171
- // Do nothing, we expected the cancellation
172
- }
173
- else if (typeof error .message === ' string' && Utils .isObject (error .response ) && [400 ,500 ].includes (error .response .status )) {
174
- this .broadcast (' viewLogs' , [{
175
- id: error .id ,
176
- code: error .code ,
177
- level: ' error' ,
178
- message: error .message ,
179
- links: error .links || []
180
- }]);
181
- Utils .error (this , " Synchronous processing failed. Please see the logs for details." , " Processing Error" );
153
+ await cancellableRequest (this , callback, ' Run' );
154
+ } catch (error) {
155
+ if (error instanceof CancellableRequestError) {
156
+ showCancellableRequestError (this , error);
182
157
}
183
158
else {
184
- Utils .exception (this , error, " Server Error" );
185
- }
186
- } finally {
187
- if (toast) {
188
- this .$snotify .remove (toast .id , true );
159
+ Utils .exception (this , error);
189
160
}
161
+
190
162
}
191
163
},
192
164
jobCreated (job ) {
0 commit comments