With the release of PolyAPI 15, we introduced the ability to directly trigger server functions via error handler configurations on the Poly Gateway. In Release 16, we extended this feature by adding UI support, making it more accessible and user-friendly. If you’re new to this feature, we recommend starting with this article to understand its purpose and the value it provides.
Now, Poly users can configure errors observed by the gateway for API and server functions to be automatically routed to a designated server function for processing. Below is a screenshot showcasing the experience of filtering down to the relevant set of errors for configuration.
Flexible Filtering for Error Events
When creating triggers, UI users can now set the source to be an Error Handler event, enabling precise control over which errors are captured. Additional filters allow you to tailor the scope:
- Context Path: Capture errors for specific function contexts. For instance, setting the context to stripe.product ensures that only errors from functions within this context are caught.
- Application IDs and User IDs: Limit error capture to specific applications or users (the invokers of functions).
- Function IDs: Focus on specific API and server functions by setting their IDs.
These filters work in combination, acting as intersections. This means that the more filters you apply, the narrower the scope of the errors captured.
Preparing the Destination Server Function
The server function configured to handle the error events must be ready to process events in the following format:
export interface ErrorEvent {
message: string;
data?: any;
status?: number;
statusText?: string;
functionId: string;
applicationId?: string;
userId?: string;
}
This structure ensures the necessary details about the error are passed to the server function, enabling you to perform actions like logging, notifying teams, or even retrying the function under certain conditions. For practical applications, refer to this article.
If you would like to see this feature in action, take a look at this demo. Note that this demo focused on capturing error events within clients directly (as opposed to triggering a server function), but the capabilities and purpose are exactly the same.
Get Started
By integrating error handling directly into your workflow, you can build more resilient and responsive systems. Interested in learning more? Contact us at hello@polyapi.io, and let’s explore how this feature can help your team.