import request from 'superagent';
import nocache from 'superagent-no-cache';

function post(url, token, data = {}) {
    let response;

    response =
        request.post(url)
            .set('Jwt', token)
            .accept('application/json')
            .type('form')
            .use(nocache)
            .send(data);

    return response;
}

function use(response, dispatch, doneType, falseType) {
    response.end((err, res) => {
        if (err) {
            dispatch({
                type: falseType,
                error: err
            });
        } else if (res.status !== 200) {
            dispatch({
                type: falseType,
                error: "Error on server side, error code: " + res.status
            });
        } else {
            let data = JSON.parse(res.text);
            if (data.error) {
                dispatch({
                    type: falseType,
                    error: data.error
                });
            } else {
                dispatch({
                    type: doneType,
                    data: data
                });
            }
        }
    });
}

export { post, use };

@@ -69,16 +69,59 @@
 -cache';
+%0Aimport * as constants from '../constants';
 %0A%0Afuncti
@@ -788,32 +788,112 @@
        %7D else %7B%0A
+            // TODO %D0%BF%D1%80%D0%BE%D0%B1%D0%BB%D0%B5%D0%BC%D0%B0 %D0%B5%D1%81%D0%BB%D0%B8 %D0%BF%D1%80%D0%B8%D1%85%D0%BE%D0%B4%D0%B8%D1%82 %D0%BD%D0%B5 %D0%9E%D0%B1%D1%8A%D0%B5%D0%BA%D1%82, %D1%82%D0%BE%D0%B3%D0%B4%D0%B0 %D0%B2%D1%81%D0%B5 %D0%BD%D0%B0%D1%85%D1%80%D0%B5%D0%BD %D0%B7%D0%B0%D0%B2%D0%B8%D1%81%D0%B0%D0%B5%D1%82%0A
             let 
@@ -921,16 +921,17 @@
 .text);%0A
+%0A
         
@@ -943,21 +943,34 @@
 f (data.
+status === %22
 error
+%22
 ) %7B%0A    
@@ -977,35 +977,235 @@
             
-dispatch(%7B%0A
+if (data.message === %22Bad jwt-token%22) %7B%0A                    dispatch(%7B%0A                        type: constants.USER_LOGGED_OUT%0A                    %7D);%0A                %7D else %7B%0A                    dispatch(%7B%0A    
             
@@ -1221,32 +1221,36 @@
 ype: falseType,%0A
+    
                 
@@ -1269,14 +1269,18 @@
 ata.
-error%0A
+message%0A  
     
@@ -1283,36 +1283,56 @@
                 
+  
 %7D);%0A
+                %7D%0A
             %7D el

Update ajax.js