@@ -13,6 +13,7 @@ import Store from "oxalis/store";
13
13
import type { OxalisState } from "oxalis/store" ;
14
14
import { connect } from "react-redux" ;
15
15
import FormattedDate from "components/formatted_date" ;
16
+ import Utils from "libs/utils" ;
16
17
17
18
type State = {
18
19
files : Array < * > ,
@@ -134,8 +135,9 @@ class NmlUploadZoneContainer extends React.PureComponent<Props, State> {
134
135
this . setState ( {
135
136
isImporting : true ,
136
137
} ) ;
138
+
137
139
try {
138
- const importActions = await Promise . all (
140
+ const { successes : importActions , errors } = await Utils . promiseAllWithErrors (
139
141
this . state . files . map ( async file => {
140
142
const nmlString = await readFileAsText ( file ) ;
141
143
try {
@@ -145,20 +147,19 @@ class NmlUploadZoneContainer extends React.PureComponent<Props, State> {
145
147
) ;
146
148
return addTreesAndGroupsAction ( trees , treeGroups ) ;
147
149
} catch ( e ) {
148
- return new Error ( `"${ file . name } " could not be parsed. ${ e . message } ` ) ;
150
+ throw new Error ( `"${ file . name } " could not be parsed. ${ e . message } ` ) ;
149
151
}
150
152
} ) ,
151
153
) ;
152
154
153
- const errors = importActions . filter ( action => action instanceof Error ) ;
154
155
if ( errors . length > 0 ) {
155
156
throw errors ;
156
157
}
157
158
158
159
// Dispatch the actual actions as the very last step, so that
159
160
// not a single store mutation happens if something above throws
160
161
// an error
161
- importActions . forEach ( action => Store . dispatch ( action ) ) ;
162
+ importActions . forEach ( actionOrError => Store . dispatch ( actionOrError ) ) ;
162
163
} catch ( e ) {
163
164
( Array . isArray ( e ) ? e : [ e ] ) . forEach ( e => Toast . error ( e . message ) ) ;
164
165
} finally {
0 commit comments