Last active
September 2, 2017 23:50
-
-
Save imkrish/d85183349d0c68c9873c361723b57d9f to your computer and use it in GitHub Desktop.
03-try-catch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const R = require('ramda') | |
// Utils | |
const log = R.tap(console.log) | |
const emptyArray = () => [] | |
// getObjectFromFile | |
const parseJSONFromFile = R.compose(JSON.parse, fs.readFileSync) | |
const handleError = R.compose(emptyArray, log) | |
const getObjectFromFile = R.tryCatch(parseJSONFromFile, handleError) | |
// Result | |
const products = getObjectFromFile('../products.json') | |
console.log(products) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment