Skip to content

Instantly share code, notes, and snippets.

@imkrish
Last active September 2, 2017 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkrish/d85183349d0c68c9873c361723b57d9f to your computer and use it in GitHub Desktop.
Save imkrish/d85183349d0c68c9873c361723b57d9f to your computer and use it in GitHub Desktop.
03-try-catch.js
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