Skip to content

Commit

Permalink
fix: more try-catch patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
LuXDAmore committed Oct 7, 2020
1 parent 7d29661 commit 0865fce
Showing 1 changed file with 77 additions and 68 deletions.
145 changes: 77 additions & 68 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,51 +179,55 @@ export default async function(
}

// API
const responses = await all(
promises,
);
try {

// Start the file creation
fileContent = responses.reduce(
(
accumulator,
{ data = {} },
index,
) => {
const responses = await all(
promises,
);

const {
id,
field: key = index,
emptyValue,
pathToData,
} = requestsInParallel[ index ]
, value = findValue(
pathToData,
data,
emptyValue
)
;

// Keep errors for later
data.error && errors.push(
`[${ id }] ${ data.error }`
);

data.errors && data.errors.length && errors.push(
... data.errors.map(
error => `[${ id }] ${ error.message }`
),
);

// Return data
return {
... accumulator,
[ key ]: value,
};
// Start the file creation
fileContent = responses.reduce(
(
accumulator,
{ data = {} },
index,
) => {

const {
id,
field: key = index,
emptyValue,
pathToData,
} = requestsInParallel[ index ]
, value = findValue(
pathToData,
data,
emptyValue
)
;

},
{},
);
// Keep errors for later
data.error && errors.push(
`[${ id }] ${ data.error }`
);

data.errors && data.errors.length && errors.push(
... data.errors.map(
error => `[${ id }] ${ error.message }`
),
);

// Return data
return {
... accumulator,
[ key ]: value,
};

},
{},
);

} finally {} // eslint-disable-line

}

Expand Down Expand Up @@ -277,40 +281,45 @@ export default async function(

}

const { data = {} } = await axiosWithConfig[ method ](
endpoint,
params,
config,
)
, newValue = findValue(
pathToData,
data,
emptyValue,
)
;

if( value && newValue ) {
try {

if(
Array.isArray(
value
const { data = {} } = await axiosWithConfig[ method ](
endpoint,
params,
config,
)
, newValue = findValue(
pathToData,
data,
emptyValue,
)
) {
;

value.push(
... newValue
);
if( value && newValue ) {

} else {
if(
Array.isArray(
value
)
) {

value.push(
... newValue
);

} else {

value = {
... value,
... newValue,
};
value = {
... value,
... newValue,
};

}

}

}
} finally {} // eslint-disable-line


// Keep errors for later
data.error && errors.push(
Expand Down

0 comments on commit 0865fce

Please sign in to comment.