Hi fauns,
I’m thinking about error handling on JavaScript SDK. For now, we only do something like this:
import { Client, query } from 'faunadb';
const client = new Client({ secret: 'secret' });
const { Select, Get, Match, Index } = query;
async function action(): Promise<void> {
try {
const request: any = await client.query(
Select(
['data'],
Get(Match(Index('papers_by_date'), 'date')))
)
// do something with `request`
} catch (err) {
// handle error
// maybe unauthorized? maybe bad request? maybe bad query?
// i don't know
}
}
action();
This can be very tricky if you need to know exactlly what type of error you have. ¿It’s on the roadmap something like this?:
//...
type Fauna.Request = { ?? }
const { data, error }: Fauna.Request = await client.query(
Select(
['data'],
Get(Match(Index('papers_by_date'), 'date')))
)
if (error) {
switch (error) {
case 'unauthorized':
// do something with especific error type
break;
case 'bad_request':
// do something with especific error type
break;
default:
break;
}
}
//...
Thanks,