Skip to content

Commit

Permalink
Better error message (patch)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrrrzzt committed Dec 15, 2019
1 parent 13ac7e0 commit d81b003
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,5 @@ documents.json
documents-copy.json
documents-done.json
documents-error.json
documents-original.json
rapport.txt
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
}
} catch (error) {
logger('error', ['index', 'document', _id, 'student', student, 'teacher', teacher, 'lookup student', error])
documentsError.push({ document, success: false, error: error })
documentsError.push({ document, success: false, error: error.message })
await writeFile('data/documents-error.json', JSON.stringify(documentsError, null, 2), 'utf-8')
}
}
Expand Down
6 changes: 5 additions & 1 deletion lib/get-tjommi-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ module.exports = async options => {
logger('info', ['lib', 'get-tjommi-data', 'student', student, 'teacher', teacher, 'success'])
if (data.length === 1) {
return data[0]
} else {
} else if (data.length > 0) {
const errorMessage = 'too many matches'
logger('error', ['lib', 'get-tjommi-data', 'student', student, 'teacher', teacher, errorMessage])
throw new Error(errorMessage)
} else if (data.length === 0) {
const errorMessage = 'student not found'
logger('error', ['lib', 'get-tjommi-data', 'student', student, 'teacher', teacher, errorMessage])
throw new Error(errorMessage)
}
} catch (error) {
logger('error', ['lib', 'get-tjommi-data', 'student', student, 'teacher', teacher, error])
Expand Down

0 comments on commit d81b003

Please sign in to comment.