Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

543
Visualizações
Javascript FileReader onerror event - how to find out what the error was?

the Javascript FileReader object supports an onerror handler that gets called when there has been an error, but the event passed in is a ProgressEvent and doesn't contain any details of the error.

How can I find out what actual error occurred?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

After RTFMing a little more closely in response to @Ariel's comment (https://developer.mozilla.org/en-US/docs/Web/API/FileReader/error), I see that FileReader has an error property as well as an error event. When the error handler is called, the the ProgressEvent passed to it is next to useless and you need to look at the error property instead.

Therefore instead of:

reader.onerror = x => { throw x }

a more appropriate response is:

reader.onerror = () => { throw reader.error }`

or if you're wrapping inside a promise (as per Javascript Promises with FileReader()), instead of:

reader.onerror = reject:

you're better off using

reader.onerror = () => reject(reader.error)

Having said that, the error property is of type DOMException which does not inherit from Error and, in my case, contained very little useful information, but it seems to be the best there is and, as far as I could tell, throwing a DOMException seems to be considered acceptable practice even though it isn't an Error

about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda