Skip to content
This repository has been archived by the owner on Nov 26, 2021. It is now read-only.

Commit

Permalink
feat: Improve API error handling (#44) - fix #43
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanjudis committed Jan 7, 2017
1 parent 3eef703 commit 787f4fd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/processor.js
Expand Up @@ -163,11 +163,32 @@ function processFile (file, options) {
const client = getContentfulClient(accessToken, spaceId, host)

return client.getEntries(query)
.catch(error => decorateAPIError(error, file))
.then(entries => mapEntriesForFile(entries.items, file, options))
.then(entries => processEntriesForFile(file, entries, options))
.then(entries => getCommonContentForSpace(entries, options))
}

/**
* Decorate the error coming from a failed
* API response with the hint that the API failed
*
* This function also throws an error to
* propagate the promise chain
*
* @param {Object} error error thrown by the API call
* @param {fiel} file file that triggered the API call
*
* @throws {Error}
*
*/
function decorateAPIError (error, file) {
throw new Error(
`Could not process file ${file._fileName}:
API error response: ${error.message}`
)
}

module.exports = {
processFile
}

0 comments on commit 787f4fd

Please sign in to comment.