Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

navigate throws error with error log showing "wth" #109

@grayson-solutions

Description

@grayson-solutions

I have a button which on click uses axios to save the form data. I have that in a try catch. The axios request works just fine, but when I try to navigate to a new "page", an error is thrown. When I catch and log the error it just shows: wth !

const SaveEvent = async () => {
        let savedOk = false
        setSaving(true)
        const data = {
            ...
        }
        try {
          const result = await axios({
            method: 'post',
            url: 'http://localhost:49505/principal/api/AddEvent',
            headers : {'content-type' : 'application/json'},
            data: JSON.stringify(data)
          })
          if (result.data === "ok") {
                alert("Evening Saved")
                savedOk = true
                navigate('/admin/events', true);
         
          }
      } catch (e) {
        console.log(e);
        alert("Error Saving Data")            
      } finally {
        if (!savedOk) setSaving(false)
      }; 
  }

...

<button className="btn right waves-effect waves-light" id="btnAddEventSave" onClick={SaveEvent}><i className="material-icons left">save</i> SAVE</button>

...

{saving &&
    <div className="progress">
        <div className="indeterminate"></div>
    </div>
    }

if I move the navigate out of the try/catch, I get an error in the console saying uncaught error...

The navigation works ok, but I don't want to have to check for a wth error in my catch. What am I doing wrong>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions