Skip to content

Instantly share code, notes, and snippets.

@jrsinclair
Created December 5, 2018 06:53
Show Gist options
  • Save jrsinclair/27a3a8785131932d3f3a81fa554d4eff to your computer and use it in GitHub Desktop.
Save jrsinclair/27a3a8785131932d3f3a81fa554d4eff to your computer and use it in GitHub Desktop.
Elegant Error Handling Code Samples
function splitCSVToRows(csvData) {
// There should always be a header row... so if there's no
// newline character, something is wrong.
return (csvData.indexOf('\n') < 0)
? left('No header row found in CSV data')
: right(csvData.split('\n'));
}
function processRows(headerFields, dataRows) {
// Note this is Array map, not Either map.
return dataRows.map(row => processRow(headerFields, row));
}
function showMessages(messages) {
return `<ul class="Messages">${messages.join('\n')}</ul>`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment