How to use the es6-promise.Promise.reject function in es6-promise

To help you get started, we’ve selected a few es6-promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DroopyTersen / spscript / dist / v1 / spselect2.js View on Github external
}
		} 
		else {
			qs = querystring(options.data)
			qs && (url += (url.indexOf('?') >= 0 ? '&' : '?') + qs)
		}

		// create XMLHttpRequest
		var http = xhr()

		// handle error
		if (http === null) {
			err = new Error("Your broswer don't support ajax!")
			isFunction(options.error) && options.error(err)
			isFunction(callback) && callback(err)
			if (typeof Promise !== "undefined") return Promise.reject(err)
			return
		}

		// open XMLHttpRequest
		http.open(method, url, options.async)

		// set request headers
		forEach(options.headers, function (value, key) {http.setRequestHeader(key, value)})

		// set response type
		options.type && (http.responseType = options.type)

		function send (resolve, reject) {

			http.onreadystatechange = function () {
				// complete
github freedomjs / freedom / providers / core / core.xhr.js View on Github external
XhrProvider.prototype.open = function(method, url, async, user, password) {
  "use strict";
  if (typeof async !== "undefined" && async !== true) {
    return PromiseCompat.reject({
      errcode: "InvalidAccessError",
      message: "async should always be set to true"
    });
  }

  // Force async to be true. undefined can lead to async=false in Chrome packaged apps
  this._xhr.open(method, url, true, user, password);
  return PromiseCompat.resolve();
};
github leidenglai / React-Koa2-SSR / server / controllers / user.js View on Github external
.then(data => {
      if (data[0]) {
        // 邮箱已存在
        return Promise.reject(statusCode.err10002)
      }
      if (data[1]) {
        // 手机号已存在
        return Promise.reject(statusCode.err10003)
      }

      return proxyUser.createUser({
        email,
        phone,
        pass,
        isNew: true
      })
    })
    .then(() => {
github staltz / xstream / tests / factory / from.ts View on Github external
it('should convert a rejected promise to a stream', (done: any) => {
    const stream = xs.from(Promise.reject('no'));

    stream.addListener({
      next: (x: string) => done('next should not be called'),
      error: (err: any) => {
        assert.strictEqual(err, 'no');
        done();
      },
      complete: () => done('complete should not be called'),
    });
  });
github ccforward / zhihu / spider / spider.js View on Github external
.catch(function(err){
                console.log(new Date() + ' refresh day data error2 ' + err)
                tmpDAO.save({aid: '', dtime: dtime});
                return Promise.reject(err);
            })
    },
github laketea / admin-demo / src / carno / utils / http / middlewares.js View on Github external
requestError(_requestError) {
      if (!hasErrorModal) {
        Modal.error({
          title: DEFAULT_REQ_ERROR,
          onOk: () => {
            hasErrorModal = false;
          }
        });
        hasErrorModal = true;
      }
      return Promise.reject(_requestError);
    }
  };
github freedomjs / freedom / providers / core / core.rtcpeerconnection.js View on Github external
RTCPeerConnectionAdapter.prototype.getStreamById = function (id) {
  return PromiseCompat.reject({
    errcode: -1,
    message: "Not Implemented"
  });
};
github intermine / im-tables / src / views / list-dialogue / base-append-dialogue.js View on Github external
const theListIsSuitable = path => function(list) {
  if (!path.isa(list.type)) { return (Promise.reject(LIST_NOT_SUITABLE)); }
} ;
github manifoldco / torus-cli / cli / lib / daemon / object.js View on Github external
Daemon.prototype.set = function (data) {
  if (!data && !data.token && !data.passphrase) {
    return Promise.reject(new TypeError(
      'Must provide object with token or passphrase properties'));
  }


  var id = uuid.v4();
  var msg = {
    type: 'request',
    id: id,
    command: 'set',
    body: {
      token: data.token,
      passphrase: data.passphrase
    }
  };
  var p = this._wrap(id);
  this.client.send(msg).catch(p.reject);
github syndesisio / syndesis-ui / e2e / common / common.steps.ts View on Github external
public async scroll(topBottom: string, leftRight: string): P {

    const size = await browser.manage().window().getSize();
    const directions: Object = {
      top: 0,
      bottom: size.height,
      left: 0,
      right: size.width,
    };
    if (!directions.hasOwnProperty(topBottom) || !directions.hasOwnProperty(leftRight)) {
      return P.reject(`unknown directions [${topBottom}, ${leftRight}`);
    }
    const x = directions[leftRight];
    const y = directions[topBottom];

    log.info(`scrolling to [x=${x},y=${y}]`);
    return browser.driver.executeScript((browserX, browserY) => window.scrollTo(browserX, browserY), x, y);
  }
}