Error handling
It is a best practice to handle API call errors gracefully using a try/catch block. This allows you to manage both network issues and application-level errors, such as when no records are found.
💡Unified Error Handling
The error handling syntax remains consistent regardless of your data source.
Whether you are querying a native Manta table or an external PostgreSQL
database, you can use the same try/catch logic. The only functional
difference is the inclusion of the db parameter for external database
requests.
TypeScript
try {
const users = await manta.fetchAllRecords({
table: "users",
fields: ["user_id", "first_name"],
page: 1,
list: 10,
});
if (users.status) {
console.log("Users found:", users.data);
console.log("Pagination:", users.meta);
} else {
console.log("No users found");
}
} catch (error) {
console.error("Error fetching users:", error.message);
}
Common error scenarios​
- Table not found: The API returns an error message such as "Table not found or access denied."
- Invalid field: If you request fields that do not exist, the API will return a successful response with an empty
dataarray for those fields. - Invalid filter: When a filter is invalid, the API returns a successful response with an empty results list.
- Relationship error: The API returns a detailed error in the relationship object, providing specific information about the issue.