Error Handling

Error handling is an important part in application development. Sircl provides extension points to add your own logic to handle errors with Javascript.

Introduction

By default, errors are "ignored": no error message or dialog is shown. It is up to you, website or app developer, to determine what action to take on error.

General error handlers

A general error handler is an error handler called to handle a "general error". This can be due to a programming error but also due to a failed request.

A general error handler is a Javascript function installed with the sircl.addErrorHandler function:

<script>
  sircl.addErrorHandler(function (code, message, data) {
    alert("Error " + code + " has occured: " + message);
  });
</script>

Following errors can be trapped by a general error handler:

Code Message Parameters Library
S121 Error executing a BeforeUnLoad handler: ... { exception, fx } core
S122 Error executing an AfterLoad content handler: ... { exception, fx } core
S123 Error executing an AfterLoad enrich handler: ... { exception, fx } core
S124 Error executing an AfterLoad process handler: ... { exception, fx } core
S125 Error executing an After history handler. { exception, fx } core
S131 Error executing a RequestProcessor step: ... { exception, fx, request } core
S141 Too many redirects. { request } core
S151 Error evaluating class action value "..." : ... { exception, element } core
S161 Error executing a Page Navigate handler. { exception, fx } core
S162 Error executing a Page Navigate cancellation handler. { exception, fx } core
S311 Change action request failed. { request } changeactions

The data is an object with properties request, exception, fx (function) and/or element as stated in the above table.

See the section about Extensibility for more information about BeforeUnload and AfterLoad handlers and RequestProcessor steps.

Errors loading page parts

Partial page loads are processed by "processing pipeline" where custom handlers can be injected. This is part of how Sircl is made extensible.

When an error occures requesting a page part (a HTTP statuscode >= 300 is returned), error handlers get injected in the processing pipeline. A processing pipeline error handler is a Javascript function registered using the sircl.addRequestHandler for the phase "onError". For instance:

<script>
  sircl.addRequestHandler("onError", function (req) {
    if (req.method === "get") {
      // Re-issue the request by the browser, to render the error page:
      window.location.href = req.action
    } else {
      // If no get request, we can not re-issue, then inform user:
      alert("An error has occured.");
    }
    // Process next handler:
    this.next(req);
  });
</script>

As all processing pipeline handlers (see more about them in the section about Extensibility), the handler function gets a request as parameter and must pass this on to the next handler using the this.next(req) method.

In the above error handler, if the request was a "get" request, it will be re-issued, but by the browser this time, ensuring a full page is requested and returned. The returned page is expected to provide information about the error.
If the request was not a "get" request (but for instance a "post" request), it cannot simply be replayed and a simple alert is shown instead. In practice, you could show an HTML 5 dialog or a Bootstrap modal window with a friendly error message and maybe even the opportunity for the user to report the error.

In Single Page mode, where a main target is defined, you could replace the content of the main target instead of performing a full page load.

The processing pipeline error handler could decide to cancel the error by calling

  req.succeeded = true;

For instance, because the handler managed to retrieve a cached version of the requested page part and it should therefore not be considered in failed state anymore.

 

Loading...