Gostaria que aparecesse no console, apenas a mensagem colocada no reject e ocultasse aquele erro de GET padrão do browser.
function loadScript(src) {
return new Promise((resolve, reject) => {
let script = document.createElement('script')
script.src = src
script.onload = resolve(script)
script.onerror = reject(console.log(new Error('Ocorreu algum erro.')))
document.head.append(script)
})
}
loadScript('msf.js')
O erro:
Error: Ocorreu algum erro.
at promise_version.html:18
at new Promise (<anonymous>)
at loadScript (promise_version.html:14)
at promise_version.html:23
GET file:///home/art/Art/promise_assync_await/msf.js net::ERR_FILE_NOT_FOUND
(anonymous) @ promise_version.html:19
loadScript @ promise_version.html:14
(anonymous) @ promise_version.html:23