1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

Add error handling

This commit is contained in:
AWolf81
2019-10-24 20:58:47 +02:00
committed by Junyoung Choi
parent 77833ff980
commit 5280b6ed63

View File

@@ -14,12 +14,18 @@ function validateUrl (str) {
}
}
const ERROR_MESSAGES = {
ENOTFOUND: 'URL not found. Please check the URL, your internet connection and try again.',
VALIDATION_ERROR: 'Please check your URL is in correct format. (Example, https://www.google.com)',
UNEXPECTED: 'Unexpected error! Please check console for details!'
}
function createNoteFromUrl (url, storage, folder, dispatch = null, location = null) {
return new Promise((resolve, reject) => {
const td = createTurndownService()
if (!validateUrl(url)) {
reject({result: false, error: 'Please check your URL is in correct format. (Example, https://www.google.com)'})
reject({result: false, error: ERROR_MESSAGES.VALIDATION_ERROR})
}
const request = url.startsWith('https') ? https : http
@@ -70,8 +76,9 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
req.on('error', (e) => {
console.error('error in parsing URL', e)
reject({result: false, error: e})
reject({result: false, error: ERROR_MESSAGES[e.code] || ERROR_MESSAGES.UNEXPECTED})
})
req.end()
})
}