Hello everyone! I was wondering, when I have a request like this;
try {
const fetchedCourseObject = await courseObject.fetch();
return fetchedCourseObject;
}
catch (error) {
throw error;
}
when does catch get activated? If the response is null or an empty array, does it consider it as a success?
The catch will be activated if an error is thrown when calling courseObject.fetch().
For Example, if courseObject has been deleted from the database and you call fetch() on it, a Parse.Error will be thrown and handled in the catch.
1 Like
So if the response is null?
I dont think courseObject.fetch() will ever return null… but if it did you could do something like:
try {
const fetchCourseObject = await courseObject.fetch();
if (fetchCourseObject === null) {
throw new Parse.Error(400, 'some error message');
}
} catch (error) {
console.log(error.message);
// this will log "some error message" to the console if courseObject.fetch() returns null
}
1 Like