From 0865fce5c4efd22d8a6e6c3f6745410df9281f7a Mon Sep 17 00:00:00 2001 From: Luca Iaconelli Date: Wed, 7 Oct 2020 15:57:46 +0200 Subject: [PATCH] fix: more try-catch patterns --- lib/module.js | 145 +++++++++++++++++++++++++++----------------------- 1 file changed, 77 insertions(+), 68 deletions(-) diff --git a/lib/module.js b/lib/module.js index f420354..1c6ad6b 100644 --- a/lib/module.js +++ b/lib/module.js @@ -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 } @@ -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(