Skip to content

Commit 5280b6e

Browse files
AWolf81Rokt33r
authored andcommitted
Add error handling
1 parent 77833ff commit 5280b6e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

browser/main/lib/dataApi/createNoteFromUrl.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,18 @@ function validateUrl (str) {
1414
}
1515
}
1616

17+
const ERROR_MESSAGES = {
18+
ENOTFOUND: 'URL not found. Please check the URL, your internet connection and try again.',
19+
VALIDATION_ERROR: 'Please check your URL is in correct format. (Example, https://www.google.com)',
20+
UNEXPECTED: 'Unexpected error! Please check console for details!'
21+
}
22+
1723
function createNoteFromUrl (url, storage, folder, dispatch = null, location = null) {
1824
return new Promise((resolve, reject) => {
1925
const td = createTurndownService()
2026

2127
if (!validateUrl(url)) {
22-
reject({result: false, error: 'Please check your URL is in correct format. (Example, https://www.google.com)'})
28+
reject({result: false, error: ERROR_MESSAGES.VALIDATION_ERROR})
2329
}
2430

2531
const request = url.startsWith('https') ? https : http
@@ -70,8 +76,9 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
7076

7177
req.on('error', (e) => {
7278
console.error('error in parsing URL', e)
73-
reject({result: false, error: e})
79+
reject({result: false, error: ERROR_MESSAGES[e.code] || ERROR_MESSAGES.UNEXPECTED})
7480
})
81+
7582
req.end()
7683
})
7784
}

0 commit comments

Comments
 (0)