make get send errors too

This commit is contained in:
Jonathan Rainville 2018-09-06 14:41:56 -04:00 committed by Pascal Precht
parent 6125329cae
commit ae4c16a47a
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
1 changed files with 9 additions and 4 deletions

View File

@ -1,16 +1,21 @@
import axios from "axios";
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)
.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) => {
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(){};
delete params.callback;
return axios.post(constants.httpEndpoint + path, params)