function done()

in modules/services/osm.js [618:662]


        function done(err, payload) {
            if (that.getConnectionId() !== cid) {
                if (callback) callback({ message: 'Connection Switched', status: -1 });
                return;
            }

            var isAuthenticated = that.authenticated();

            // 400 Bad Request, 401 Unauthorized, 403 Forbidden
            // Logout and retry the request..
            if (isAuthenticated && err && err.status &&
                    (err.status === 400 || err.status === 401 || err.status === 403)) {
                that.logout();
                that.loadFromAPI(path, callback, options);

            // else, no retry..
            } else {
                // 509 Bandwidth Limit Exceeded, 429 Too Many Requests
                // Set the rateLimitError flag and trigger a warning..
                if (!isAuthenticated && !_rateLimitError && err && err.status &&
                        (err.status === 509 || err.status === 429)) {
                    _rateLimitError = err;
                    dispatch.call('change');
                    that.reloadApiStatus();

                } else if ((err && _cachedApiStatus === 'online') ||
                    (!err && _cachedApiStatus !== 'online')) {
                    // If the response's error state doesn't match the status,
                    // it's likely we lost or gained the connection so reload the status
                    that.reloadApiStatus();
                }

                if (callback) {
                    if (err) {
                        return callback(err);
                    } else {
                        if (path.indexOf('.json') !== -1) {
                            return parseJSON(payload, callback, options);
                        } else {
                            return parseXML(payload, callback, options);
                        }
                    }
                }
            }
        }