Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions browser/main/lib/dataApi/createNoteFromUrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ function validateUrl (str) {
}
}

const ERROR_MESSAGES = {
ENOTFOUND: 'URL not found. Please check the URL, or your internet connection and try again.',
VALIDATION_ERROR: 'Please check if the URL follows this format: 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
Expand Down Expand Up @@ -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()
})
}
Expand Down