mirror of https://github.com/embarklabs/embark.git
make get send errors too
This commit is contained in:
parent
6125329cae
commit
ae4c16a47a
|
@ -1,16 +1,21 @@
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import constants from '../constants';
|
import constants from '../constants';
|
||||||
|
|
||||||
function get(path, params, endpoint) {
|
function get(path, params = {}, endpoint) {
|
||||||
|
const callback = params.callback || function(){};
|
||||||
return axios.get((endpoint || constants.httpEndpoint) + path, params)
|
return axios.get((endpoint || constants.httpEndpoint) + path, params)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
return {response, error: null};
|
const data = (response.data && response.data.error) ? {error: response.data.error} : {response, error: null};
|
||||||
|
callback(data.error, data.response);
|
||||||
|
return data;
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
return {response: null, error: error.message || 'Something bad happened'};
|
const data = {response: null, error: error.message || 'Something bad happened'};
|
||||||
|
callback(data.error, data.response);
|
||||||
|
return data;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function post(path, params) {
|
function post(path, params = {}) {
|
||||||
const callback = params.callback || function(){};
|
const callback = params.callback || function(){};
|
||||||
delete params.callback;
|
delete params.callback;
|
||||||
return axios.post(constants.httpEndpoint + path, params)
|
return axios.post(constants.httpEndpoint + path, params)
|
||||||
|
|
Loading…
Reference in New Issue