New to Telerik Reporting? Download free 30-day trial

Handling errors occurring in a Custom Resolver used by a Reporting REST Service

Environment

Product Progress® Telerik® Reporting
Report Viewer HTML5-based Report Viewers

Description

Handling errors occurring in a Custom Resolver used by a Reporting REST Service. In this article, we will explain how to handle errors that fire due to errors with the report's processing and errors that cause the report processing to not start altogether.

Solution

In general, a .CS Type Report has an Error event which fires due to problems with the report processing. Such errors can be handled in the report's Error event or/and in the HTML5 Viewer's error event.

For example:

//the report
public partial class ReportTest : Telerik.Reporting.Report
    {
        public ReportTest()
        {
            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();
            this.Error += new Telerik.Reporting.ErrorEventHandler(this.rptTest_Error);           
        }
        private void rptTest_Error(object sender, ErrorEventArgs eventArgs)
        {
            eventArgs.Cancel = true;
            throw new Exception("Manually cancelled.");
        }
    }

The HTML5 Viewer:

//the client
$(document).ready(function () {
       $("#reportViewer1")
           .telerik_ReportViewer({
               serviceUrl: "api/reports/",
               templateUrl: 'ReportViewer/templates/telerikReportViewerTemplate.html',
               reportSource: {
                   report: "Telerik.Reporting.Examples.CSharp.ReportCatalog, CSharp.ReportLibrary",
                   parameters: { }
               },
               viewMode: telerikReportViewer.ViewModes.INTERACTIVE,
               scaleMode: telerikReportViewer.ScaleModes.SPECIFIC,
               scale: 1.0,
              error: function (e, args) {
                  //hide the yellow message box
                  $('.trv-error-pane').toggle();
                  //display the error message with via custom UI            
                  alert("Error!");
               }
           });
   });

If you use a custom resolver for your Reporting REST Service, the report processing will not be started. Such errors can be caught and handled in the first request sent by the HTML5 Viewer to the Reporting REST service e.g. ReportsControllerBase.GetParameters method - the request for information about the report's parameter.

For example:

public override System.Net.Http.HttpResponseMessage GetParameters(string clientID, ClientReportSource reportSource)
{
    try {
        return base.GetParameters(clientID, reportSource);
    } catch (Exception ex) {
        throw new Exception("Report resolving error.");
    }
}

The above lines will override the default behavior of the ReportsControllerBase.GetParameters method (the Reporting REST service).

The error will be returned to the HTML5 Viewer(client), where it can be handled further in the viewer's error event. Without additional handling, the error will appear in an yellow message box in the viewer's page area.

Note
The HTML5 Viewer's error event can't be used for handling errors that are result of issues on connecting to the Reporting REST Service.

In this article