I have an onCall
Firebase Cloud Function named getZohoDeskTicketById
that throws an error like this:
throw new functions.https.HttpsError(
'unknown',
error.response.data.errorCode,
error.response.data
);
And I am calling it like this:
import { httpsCallable, FunctionsError } from 'firebase/functions';
// ...
const getZohoDeskTicketById = httpsCallable(functions, 'getZohoDeskTicketById');
const handleClick = async () => {
try {
const result = await getZohoDeskTicketById({
ticketId: '345112301899997',
});
console.log(result);
} catch (error) {
if (error instanceof FunctionsError) { // TypeScript warning here
console.log(error.code); // TypeScript warning here
console.log(error.message); // TypeScript warning here
console.log(error.details); // TypeScript warning here
}
}
};
But I'm having trouble with narrowing down the catch
.
FunctionsError
has a TypeScript warning of 'FunctionsError' only refers to a type, but is being used as a value here. ts(2693)
and
error
on each of my console.log's has a TypeScript warning of Object is of type 'unknown'.ts(2571)
So what is the correct way of narrowing down this error?