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

127
Visualizações
Throwing an error outside of onMount within Svelte

I am wanting to throw an error within the onMount function when the page loads that will then take the page to the __error.svelte page for the error to be handled.

I am using the custom error class

class CustomError extends Error {
    constructor(message) {
      super(message); // (1)
      this.status = 401; // (2)
    }
}

The code I have so far is, which throws the error to the console only and does not redirect the page to __error.svelte.

onMount(()=> {
    throw new CustomError("Test");
})

The code that does what I am after is. This works when run outside of any functions and redirects the page to __error.svelte with the message:

throw new CustomError("Test");

Is there a way to structure this so that it will throw the error within the page rather than the function? I have tried a try/catch statement which doesn't work.

Or is there an alternative method to target the __error.svelte file with the custom error message I am wanting?

about 4 years ago · Juan Pablo Isaza
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