diff --git a/package.json b/package.json index 3bde410..a373491 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@bytedo/fetch", - "version": "2.0.1", + "version": "2.0.2", "description": "全新的ajax封装。分2个版本, 一个基于XMLHttpRequest, 一个基于window.fetch", "main": "dist/index.js", "files": [ diff --git a/src/index.js b/src/index.js index 2463bfa..ea6925e 100644 --- a/src/index.js +++ b/src/index.js @@ -282,15 +282,21 @@ class _Request { __success__(isSucc, result) { var { body, status, statusText, headers } = result var response = new Response(body, { status, statusText, headers }) + var _type if (this._owner._inject_res) { response = this._owner._inject_res(response) + _type = toS.call(response) } if (isSucc) { this.defer.resolve(response) } else { - this.defer.reject(response) + if (_type === '[object Promise]') { + return response.then(_ => this.defer.reject(_)).catch(_ => this.defer.reject(_)) + } else { + this.defer.reject(response) + } } delete this.xhr delete this.options diff --git a/src/next.js b/src/next.js index 24a5d61..01f851b 100644 --- a/src/next.js +++ b/src/next.js @@ -179,13 +179,19 @@ class _Request { .then(r => { clearTimeout(this.timer) let isSucc = r.status >= 200 && r.status < 400 + let _type if (this._owner._inject_res) { r = this._owner._inject_res(r) + _type = toS.call(r) } if (isSucc) { return r } else { - return Promise.reject(r) + if (_type === '[object Promise]') { + return r.then(_ => Promise.reject(_)) + } else { + return Promise.reject(r) + } } }) .catch(e => {