PS C:\Users\rebeca.oliveira\Documents\GitHub\2708-node-lib-md> npm run cli:valida
> 2708-node-lib-md@1.0.0 cli:valida
> node ./src/cli.js ./arquivos/texto.md --valida
olá mundo
node:internal/deps/undici/undici:11457
Error.captureStackTrace(err, this);
^
TypeError: Failed to parse URL from [object Object]
at Object.fetch (node:internal/deps/undici/undici:11457:11)
at async file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/http-validacao.js:9:30
at async Promise.all (index 0)
at async checaStatus (file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/http-validacao.js:6:23)
at async listaValidada (file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/http-validacao.js:18:20)
at async imprimeLista (file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/cli.js:14:13) {
[cause]: TypeError [ERR_INVALID_URL]: Invalid URL
at new NodeError (node:internal/errors:399:5)
at new URL (node:internal/url:560:13)
at new Request (node:internal/deps/undici/undici:7041:25)
at fetch2 (node:internal/deps/undici/undici:10598:25)
at Object.fetch (node:internal/deps/undici/undici:11455:18)
at fetch (node:internal/process/pre_execution:230:25)
at file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/http-validacao.js:9:36
at Array.map (<anonymous>)
at checaStatus (file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/http-validacao.js:8:19)
at listaValidada (file:///C:/Users/rebeca.oliveira/Documents/GitHub/2708-node-lib-md/src/http-validacao.js:18:26) {
input: '[object Object]',
code: 'ERR_INVALID_URL'
}
}
Node.js v18.16.0
O erro acima acontece ao executar essa parte do curso:
-> http-validacao.js:
function extraiLinks(arrLinks){
return arrLinks.map((objetoLink) => Object.values(objetoLink).join());
}
async function checaStatus(listaURLs){
const arrStatus = await Promise
.all(
listaURLs.map(async (url) => {
const response = await fetch(url);
return response.status;
})
)
return arrStatus;
}
export default async function listaValidada(listaDeLinks){
const links = extraiLinks(listaDeLinks);
const status = await checaStatus(links);
return status;
}
-> cli.js:
async function imprimeLista(valida, resultado, identificador = '') {
if(valida){
console.log(
chalk.yellow('lista validada'),
chalk.black.bgGreen(identificador),
await listaValidada(resultado)
);
} else{
console.log(
chalk.yellow('lista de links'),
chalk.black.bgGreen(identificador),
resultado
);
}
}
Isso no módulo 05, aula 05. O código está idêntico ao sugerido na aula