text: // Generated by CoffeeScript 2.6.1
  (function() {
    /* jshint node:true */
    /* jshint -W097 */
    'use strict';
    var RetsError, RetsParamError, RetsPermissionError, RetsProcessingError, RetsReplyError, RetsServerError, ensureRetsError, getErrorMessage, headersHelper, replyCodes, util;
  
    replyCodes = require('./replyCodes');
  
    headersHelper = require('./headers');
  
    util = require('util');
  
    getErrorMessage = function(err) {
      var inspect;
      if (err == null) {
        return JSON.stringify(err);
      }
      if (err.message) {
        return err.message;
      }
      if (err.toString() === '[object Object]') {
        inspect = util.inspect(err, {
          depth: null
        });
        return inspect.replace(/,?\n +\w+: undefined/g, ''); // filter out unnecessary fields
      } else {
        return err.toString();
      }
    };
  
    RetsError = class RetsError extends Error {};
  
    RetsReplyError = class RetsReplyError extends RetsError {
      constructor(retsContext, replyCode, replyText) {
        super();
        this.replyCode = replyCode;
        this.replyText = replyText;
        this.name = 'RetsReplyError';
        this.replyTag = replyCodes.tagMap[this.replyCode] != null ? replyCodes.tagMap[this.replyCode] : 'unknown reply code';
        ({retsMethod: this.retsMethod, queryOptions: this.queryOptions, headerInfo: this.headerInfo} = retsContext);
        this.message = `RETS Server reply while attempting ${this.retsMethod} - ReplyCode ${this.replyCode} (${this.replyTag}); ReplyText: ${this.replyText}`;
        Error.captureStackTrace(this, RetsReplyError);
      }
  
    };
  
    RetsServerError = class RetsServerError extends RetsError {
      constructor(retsContext, httpStatus, httpStatusMessage) {
        super();
        this.httpStatus = httpStatus;
        this.httpStatusMessage = httpStatusMessage;
        this.name = 'RetsServerError';
        ({retsMethod: this.retsMethod, queryOptions: this.queryOptions, headerInfo: this.headerInfo} = retsContext);
        this.message = `RETS Server error while attempting ${this.retsMethod} - HTTP Status ${this.httpStatus} returned (${this.httpStatusMessage})`;
        Error.captureStackTrace(this, RetsServerError);
      }
  
    };
  
    RetsProcessingError = class RetsProcessingError extends RetsError {
      constructor(retsContext, sourceError) {
        super();
        this.sourceError = sourceError;
        this.name = 'RetsProcessingError';
        ({retsMethod: this.retsMethod, queryOptions: this.queryOptions, headerInfo: this.headerInfo} = retsContext);
        this.message = `Error while processing RETS response for ${this.retsMethod} - ${getErrorMessage(this.sourceError)}`;
        Error.captureStackTrace(this, RetsProcessingError);
      }
  
    };
  
    RetsParamError = class RetsParamError extends RetsError {
      constructor(message) {
        super();
        this.message = message;
        this.name = 'RetsParamError';
        Error.captureStackTrace(this, RetsParamError);
      }
  
    };
  
    RetsPermissionError = class RetsPermissionError extends RetsError {
      constructor(missing = []) {
        super();
        this.name = 'RetsPermissionError';
        this.message = "Login was successful, but this account does not have the proper permissions.";
        if (missing.length) {
          this.message += ` Missing the following permissions: ${missing.join(', ')}`;
        }
        Error.captureStackTrace(this, RetsPermissionError);
      }
  
    };
  
    ensureRetsError = function(retsContext, error) {
      if (error instanceof RetsError) {
        return error;
      } else {
        return new RetsProcessingError(retsContext, error);
      }
    };
  
    module.exports = {RetsError, RetsReplyError, RetsServerError, RetsProcessingError, RetsParamError, RetsPermissionError, ensureRetsError, getErrorMessage};
  
  }).call(this);
  