code: function safelyReject (deferred, error, prefix) {
      var errorMsg;
      if (error.retError === undefined) {
          errorMsg = error.toString();
      } else {
          errorMsg = error.retError.toString();
      }
  
      if (prefix === undefined) {
          deferred.reject(errorMsg);
      } else {
          deferred.reject(prefix + errorMsg);
      }
  }
docs: Reject a deferred / promise because of an error.
  
  @param {q.deferred} deferred The deferred whose promise should be rejected.
  @param {Object} error Error object optionally with a retError attribute. If
  there is a retError attribute on the provided error object, that
  retError will be the reported value of the error. Otherwise the error's
  toString method will be used.
  @param {String} prefix Optional string that will be prepended to the error
  message the provided deferred execution / promise will be rejected with.
  If not provided, the error number / message provided by the error's
  retError or toString method will be used.