This is how my upload function looks like at the moment. I'm using apollo mutation in that to upload a file.
I do not understand how to use try/catch and catch of the promise (which client.mutate()
is) correctly.
Also I declared the upload function as async
.
So I guess I'm mixing some things up :-(
How do I catch errors correctly?
Do I need both catches? Shouldn't I replace try/catch if I'm using a async function?
export default async function upload (client) {
try {
return client.mutate({
mutation: uploadsMutation
}).catch(err => {
console.error(err)
})
} catch (error) {
Alert.alert('Error', 'Could not upload files')
}
}