How to Monitor & Configure Alerts for Worker Metrics (Errors and Exceptions)

For Workers & Pages, what is the name of the domain?

mydomain.com

What is the issue or error you’re encountering

How can I configure alerts in Cloudflare for Worker metrics, specifically to notify me if there are errors such as client disconnected or exceptions thrown by a Worker? I’ve reviewed the notification settings, but I didn’t find an option for setting up alerts based on workers metrics at this level. Any suggestions or best practices for monitoring and alerting on Worker metrics would be greatly appreciated. Thank you!

Screenshot of the error

Hi there,

You can easily handle exceptions in your Worker code by using statements such as try…catch to ensure that if an exception is thrown in your code then it will be caught and handled gracefully.

For example, wrapping code that could trigger an exception as follows:

try { // potential exception in this code block myfunction(); } catch (error) { // if an exception was thrown, catch the error in this block console.error(error); }

Alternatively, you can also use worker logs:

you would add the event.passThroughOnException() function to the Fetch addEventListener as shown below:

addEventListener("fetch", event => { event.passThroughOnException() event.respondWith(handleRequest(event.request)) })

Take care.