Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

124
Vistas
Try-Catch block within a handler does not work depending on whether 'await' is used or not

I'm using Axios to handle my server calls. See below for where I call the server.

 export async function deleteProject(projectId) {
  return await axios({
    url: config.projectsEndpoint + "/" + projectId.projectId,
    method: "DELETE",
  });
}

I have an event handler that deletes a project and it includes a try-catch block. Funny enough, when I preface the deleteProject() function with await, the try part of my block does not work, but the catch part does. My toast notifications appear beautifully. When I take away await, the try part of my block works but my catch toast notifications do not appear. Please see below for the handler.

handleArchive = async project => {
      const originalProjects = this.state.projects;

      const projects = originalProjects.filter(p =>
        p.projectId !== project);
        this.setState({ projects })

      try {
      await deleteProject(project)
      console.log(project)
      console.log(project)
      } catch (ex) {
        if (ex.response && ex.response.status === 404) {
          toast.error("This project may have already been deleted");
        this.setState({ projects: originalProjects })
      }
        else if (ex.response && ex.response.status === 400) {
          toast.error("Oops! We are having trouble deleting that project.");

        this.setState({ projects: originalProjects })
      }
     }
    }

Also, here is where I call the onClick event.

{
      key: 'archive',
      content: project=>
      <button
      style={{color: "white"}}
      onClick={() => this.props.onArchive(project.projectId)}
      className="btn btn-sm"
      href="#">
          <i
          className="fa fa-trash-o fa-lg m-1">
          </i>
          Archive
      </button>
    }

I'm getting a 400 error with this handler setup as well. Please let me know if you need more information. Any help is appreciated, I am so lost.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda