Skip to content

Commit bb622ce

Browse files
committed
Fix version number being undefined when crate only has unstable versions
1 parent a13a6da commit bb622ce

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

app/routes/crate/version.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ export default Ember.Route.extend({
3535
return result;
3636
};
3737

38+
const fetchCrateDocumentation = () => {
39+
if (!crate.get('documentation')) {
40+
let crateName = crate.get('name');
41+
let crateVersion = params.version_num;
42+
ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`)
43+
.then((r) => {
44+
if (r.length > 0 && r[0].build_status === true) {
45+
crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`);
46+
}
47+
});
48+
}
49+
};
50+
3851
// Fallback to the crate's last stable version
3952
// If `max_version` is `0.0.0` then all versions have been yanked
4053
if (!requestedVersion && maxVersion !== '0.0.0') {
@@ -52,10 +65,13 @@ export default Ember.Route.extend({
5265
} else {
5366
params.version_num = latestStableVersion.get('num');
5467
}
55-
});
68+
}).then(fetchCrateDocumentation);
5669
} else {
5770
params.version_num = maxVersion;
71+
fetchCrateDocumentation();
5872
}
73+
} else {
74+
fetchCrateDocumentation();
5975
}
6076

6177
controller.set('crate', crate);
@@ -68,17 +84,6 @@ export default Ember.Route.extend({
6884
.finally(() => controller.set('fetchingFollowing', false));
6985
}
7086

71-
if (!crate.get('documentation')) {
72-
let crateName = crate.get('name');
73-
let crateVersion = params.version_num;
74-
ajax(`https://docs.rs/crate/${crateName}/${crateVersion}/builds.json`)
75-
.then((r) => {
76-
if (r.length > 0 && r[0].build_status === true) {
77-
crate.set('documentation', `https://docs.rs/${crateName}/${crateVersion}/`);
78-
}
79-
});
80-
}
81-
8287
// Find version model
8388
return crate.get('versions')
8489
.then(versions => {

0 commit comments

Comments
 (0)