Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!