From 977470ca7490b1a5fd351b4e6db4bba8bdd4a596 Mon Sep 17 00:00:00 2001 From: Yongfeng LI Date: Tue, 15 May 2018 14:37:03 +0800 Subject: [PATCH] normalize connection request result --- src/client.js | 2 +- src/connection.js | 10 +++++++++- src/index.js | 4 ++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index 14e2e1c..e3c708c 100644 --- a/src/client.js +++ b/src/client.js @@ -21,4 +21,4 @@ class Client { } } -export default Client +module.exports = Client diff --git a/src/connection.js b/src/connection.js index 86589ba..effda3c 100644 --- a/src/connection.js +++ b/src/connection.js @@ -22,7 +22,15 @@ class Connection { config.headers['Authorization'] = `Basic ${btoa(this.token)}` } - return axios.request(config) + return axios.request(config).then(resp => { + if (resp.data.status === 'fail') { + throw resp.data.msg + } else if (resp.data.status === 'success') { + return resp.data.data + } + + return resp.data + }) } } diff --git a/src/index.js b/src/index.js index 25dda8d..7b96260 100644 --- a/src/index.js +++ b/src/index.js @@ -1,5 +1,5 @@ -import Client from './client' +const Client = require('./client') -export default { +module.exports = { Client } -- 2.11.0