Customizing Triage Rules with Javascript

This guide assume you are familiar with Error Triage. If not, please review Triaging Errors and Sankey Analysis first.

Create the Script

Moesif automatically triages your API errors into buckets for easier organization of issues. The default settings should be fine for most users, but if you do not like the default logic for triaging errors, you can override the logic with a custom javascript function to suit your needs better.

Searching REST API logs

The function takes two inputs event and buckets

  • The event argument is the new error event that needs to be triaged
  • The buckets argument is a list of existing buckets to pick from.

The function must either return:

  • One of the existing buckets or
  • null or undefined if you want the event to be placed in a brand new bucket.

Your Javascript code must be ECMAScript version 5.1 or earlier. The Moesif sandbox is not compatible with EMCA 6. Which means you cannot use arrow functions -> and other newer features.

The below example javascript matches against buckets using HTTP Verb, Route, and Response Status, If no match, return undefined to create a new bucket.

function (event, buckets) {
   for (var i in buckets) {
     if (buckets[i].status == event.response.status &&
         buckets[i].verb == event.request.verb &&
         buckets[i].route == event.request.route) {
       return buckets[i];
   return undefined;

Errors in your code can cause events to not be triaged correctly. Use the built-in test function to ensure your code outputs correct result.


When you click test, a modal will show up with the two input arguments, event, and buckets. You can modify the JSON to suit your test for different scenarios. Once your input is ready, run the test and inspect the function output. As a reminder, null output will create a new bucket.


When you click delete, the function will be reset and triage bucket matching will return to Moesif’s default logic.