Is there some way to catch when the moralis SDK fails to upload to the database when using setUserData()
in react-moralis
?
I tried the following, but this does not catch when there are errors.
const {user, setUserData, userError, isUserUpdating} = useMoralis()
const doUpdate = (data) => {
console.log("Submitting:")
console.log(data)
setUserData(data)
.then((response) => {
console.log("Sucessfully updated")
console.log(response)
})
.catch((response) => {
console.log("Failed update")
console.log(response)
})
}
I also tried the following, but it seems to only capture the errors in a delayed way. Eg,
-
Call #1 (with intentionally good request) -
"Sucessfully updated"
-
Call #2 (with intentionally bad request) -
"Sucessfully updated"
-
Call #3 (with intentionally bad request) -
"User Error flagged"
-
Call #4 (with intentionally good request) -
"User Error flagged"
-
Call #5 (with intentionally good request) -
"Sucessfully updated"
const {user, setUserData, userError, isUserUpdating} = useMoralis()
const doUpdate = (data) => {
console.log("Submitting:")
console.log(data)
setUserData(data)
.then((response) => {
if (userError){
console.log("User Error flagged")
console.log(response)
} else {
console.log("Sucessfully updated")
console.log(response)
}
})
.catch((response) => {
console.log("Failed update")
console.log(response)
})
}
Is there some better approach?
System info
Using these npm package versions:
"moralis": "0.0.52",
"react-moralis": "0.2.3",