|
@@ -2,41 +2,41 @@ import UserService from './UserService';
|
|
|
|
|
|
function checkIt(resp) {
|
|
function checkIt(resp) {
|
|
if ( Math.parseInt(resp.status / 100, 10) === 2) {
|
|
if ( Math.parseInt(resp.status / 100, 10) === 2) {
|
|
- return resp;
|
|
|
|
- } else {
|
|
|
|
- throw resp;
|
|
|
|
- }
|
|
|
|
|
|
+ return resp;
|
|
|
|
+ } else {
|
|
|
|
+ throw resp;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
function catchIt(err) {
|
|
function catchIt(err) {
|
|
- if ( Math.parseInt(err.status / 500, 10) === 5 ){
|
|
|
|
- return err;
|
|
|
|
- } else {
|
|
|
|
- throw err;
|
|
|
|
- }
|
|
|
|
|
|
+ if ( Math.parseInt(err.status / 500, 10) === 5 ){
|
|
|
|
+ return err;
|
|
|
|
+ } else {
|
|
|
|
+ throw err;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
class Net {
|
|
class Net {
|
|
- constructor(baseURL) {
|
|
|
|
- this.baseURL = baseURL;
|
|
|
|
- }
|
|
|
|
|
|
+ constructor(baseURL) {
|
|
|
|
+ this.baseURL = baseURL;
|
|
|
|
+ }
|
|
|
|
|
|
- get(url) {
|
|
|
|
- url = this.baseURL + url;
|
|
|
|
- return window.fetch(url, {method: 'GET'}).then(checkIt).catch(catchIt);
|
|
|
|
- }
|
|
|
|
|
|
+ get(url) {
|
|
|
|
+ url = this.baseURL + url;
|
|
|
|
+ return window.fetch(url, {method: 'GET'}).then(checkIt).catch(catchIt);
|
|
|
|
+ }
|
|
|
|
|
|
- post(url, body) {
|
|
|
|
- let urb = this.baseURL + url;
|
|
|
|
- return window.fetch(urb, {
|
|
|
|
- method: 'POST',
|
|
|
|
- headers: {
|
|
|
|
- 'Content-Type':'application/json',
|
|
|
|
- 'Token' : UserService.getToken() || ''
|
|
|
|
- },
|
|
|
|
- body: JSON.stringify(body)
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
|
|
+ post(url, body) {
|
|
|
|
+ let urb = this.baseURL + url;
|
|
|
|
+ return window.fetch(urb, {
|
|
|
|
+ method: 'POST',
|
|
|
|
+ headers: {
|
|
|
|
+ 'Content-Type':'application/json',
|
|
|
|
+ 'Token' : UserService.getToken() || ''
|
|
|
|
+ },
|
|
|
|
+ body: JSON.stringify(body)
|
|
|
|
+ });
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
export default new Net('/api/');
|
|
export default new Net('/api/');
|