mirror of https://github.com/docker/docs.git
Cleaned up request and added try-catch for json parse of orgs
This commit is contained in:
parent
67d9a9989f
commit
6aa6faf803
|
|
@ -119,99 +119,84 @@ module.exports = {
|
||||||
// Returns the base64 encoded index token or null if no token exists
|
// Returns the base64 encoded index token or null if no token exists
|
||||||
repos: function (callback) {
|
repos: function (callback) {
|
||||||
repositoryServerActions.reposLoading({repos: []});
|
repositoryServerActions.reposLoading({repos: []});
|
||||||
|
let namespaces = [];
|
||||||
|
// Get Orgs for user
|
||||||
hubUtil.request({
|
hubUtil.request({
|
||||||
url: `${REGHUB2_ENDPOINT}/namespaces/`
|
url: `${REGHUB2_ENDPOINT}/user/orgs/?page_size=50`
|
||||||
}, (error, response, body) => {
|
}, (orgError, orgResponse, orgBody) => {
|
||||||
if (error) {
|
if (orgError) {
|
||||||
repositoryServerActions.error({error});
|
repositoryServerActions.error({orgError});
|
||||||
if (callback) {
|
if (callback) {
|
||||||
return callback(error);
|
return callback(orgError);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (orgResponse.statusCode !== 200) {
|
||||||
if (response.statusCode !== 200) {
|
|
||||||
let generalError = new Error('Failed to fetch repos');
|
let generalError = new Error('Failed to fetch repos');
|
||||||
repositoryServerActions.error({error: generalError});
|
repositoryServerActions.error({error: generalError});
|
||||||
if (callback) {
|
if (callback) {
|
||||||
return callback({error: generalError});
|
callback({error: generalError});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
let data = JSON.parse(body);
|
|
||||||
let namespaces = data.namespaces;
|
|
||||||
|
|
||||||
// Get Orgs for user
|
|
||||||
hubUtil.request({
|
|
||||||
url: `${REGHUB2_ENDPOINT}/user/orgs/?page_size=50`
|
|
||||||
}, (orgError, orgResponse, orgBody) => {
|
|
||||||
if (orgError) {
|
|
||||||
repositoryServerActions.error({orgError});
|
|
||||||
if (callback) {
|
|
||||||
return callback(orgError);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (orgResponse.statusCode !== 200) {
|
|
||||||
let generalError = new Error('Failed to fetch repos');
|
|
||||||
repositoryServerActions.error({error: generalError});
|
|
||||||
if (callback) {
|
|
||||||
return callback({error: generalError});
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
let orgs = JSON.parse(orgBody);
|
let orgs = JSON.parse(orgBody);
|
||||||
orgs.results.map((org) => {
|
orgs.results.map((org) => {
|
||||||
namespaces.push(org.orgname);
|
namespaces.push(org.orgname);
|
||||||
});
|
});
|
||||||
|
// Add current user
|
||||||
|
namespaces.push(hubUtil.username());
|
||||||
|
} catch(jsonError) {
|
||||||
|
repositoryServerActions.error({jsonError});
|
||||||
|
if (callback) {
|
||||||
|
return callback(jsonError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async.map(namespaces, (namespace, cb) => {
|
|
||||||
hubUtil.request({
|
|
||||||
url: `${REGHUB2_ENDPOINT}/repositories/${namespace}`
|
|
||||||
}, (error, response, body) => {
|
|
||||||
if (error) {
|
|
||||||
repositoryServerActions.error({error});
|
|
||||||
if (callback) {
|
|
||||||
return callback(error);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (response.statusCode !== 200) {
|
async.map(namespaces, (namespace, cb) => {
|
||||||
repositoryServerActions.error({error: new Error('Could not fetch repository information from Docker Hub.')});
|
hubUtil.request({
|
||||||
return null;
|
url: `${REGHUB2_ENDPOINT}/repositories/${namespace}`
|
||||||
}
|
}, (error, response, body) => {
|
||||||
|
if (error) {
|
||||||
let data = JSON.parse(body);
|
repositoryServerActions.error({error});
|
||||||
cb(null, data.results);
|
|
||||||
});
|
|
||||||
}, (error, lists) => {
|
|
||||||
if (error) {
|
|
||||||
repositoryServerActions.error({error});
|
|
||||||
if (callback) {
|
|
||||||
return callback(error);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
let repos = [];
|
|
||||||
for (let list of lists) {
|
|
||||||
repos = repos.concat(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
_.each(repos, repo => {
|
|
||||||
repo.is_user_repo = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
repositoryServerActions.reposUpdated({repos});
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
return callback(null, repos);
|
callback(error);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.statusCode !== 200) {
|
||||||
|
repositoryServerActions.error({error: new Error('Could not fetch repository information from Docker Hub.')});
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = JSON.parse(body);
|
||||||
|
cb(null, data.results);
|
||||||
});
|
});
|
||||||
|
}, (error, lists) => {
|
||||||
|
if (error) {
|
||||||
|
repositoryServerActions.error({error});
|
||||||
|
if (callback) {
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let repos = [];
|
||||||
|
for (let list of lists) {
|
||||||
|
repos = repos.concat(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
_.each(repos, repo => {
|
||||||
|
repo.is_user_repo = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
repositoryServerActions.reposUpdated({repos});
|
||||||
|
if (callback) {
|
||||||
|
return callback(null, repos);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue