# Source: bemap-service.js

    /**
     * BeNomad BeMap JavaScript API - Service
     */

    /**
     * @classdesc
     * Base class for BeMap service.
     * @public
     * @constructor
     * @abstract
     * @param {bemap.Context} context BeMap-JS-API Context. Mandatory.
     * @param {object} options see below the available values.
     */
    bemap.Service = function(context, options) {
      var opts = options || {};

      /**
       * @type {bemap.Context}
       * @protected
       */
      this.ctx = context;

      if (context === undefined || !bemap.inheritsof(context, bemap.Context)) {
        console.error("Context is required!");
        return;
      }
    };

    /**
     * Check if BeMap return an error or exception.
     * @protected
     * @return {boolean} Return true if an error or exception was detected, otherwise false.
     **/
    bemap.Service.prototype.checkErrorParser = function(xhr, doc, options) {
      var opts = options || {};

      if (doc.error) {
        var errorDoc = doc.error;
        var error = new bemap.Error({
          code: errorDoc.code,
          message: errorDoc.message
        });
        if (opts.failed) {
          opts.failed(error, doc, xhr);
        } else {
          console.error("Error code " + error.getCode() + ", message: " + error.getMessage());
        }
        return true;
      }

      var bnd = doc.BND;
      if (bnd) {
        if (bnd.action === 'exceptionReport') {
          var exceptionDoc = bnd.exception;
          var exception = new bemap.Error({
            code: exceptionDoc.code,
            message: exceptionDoc.message
          });
          if (opts.failed) {
            opts.failed(exception, doc, xhr);
          } else {
            console.error("Error code " + exception.getCode() + ", message: " + exception.getMessage());
          }
          return true;
        }
      } else {
        var NoBndError = new bemap.Error({
          code: "NO_BND_OBJECT",
          message: "No BND object was returned"
        });
        if (opts.failed) {
          opts.failed(NoBndError, doc, xhr);
        } else {
          console.error("Error code " + NoBndError.getCode() + ", message: " + NoBndError.getMessage());
        }
        return true;
      }

      return false;
    };