Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Avoid operating on empty data from API #1

Merged
merged 2 commits into from

2 participants

@evocateur

I was fiddling with it and found that a request for a valid version (e.g., 3.5.0pr1) could return an empty data set. It's silly to keep working, in this case.

Also, modify the versioning of ejs dependency so we can pick up the latest version.

@rgrove rgrove merged commit f31e18c into from
@rgrove

Thanks!

@evocateur

No problem, glad I could help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 5 deletions.
  1. +13 −4 build.js
  2. +1 −1  package.json
View
17 build.js
@@ -36,7 +36,9 @@ var ejs = require('ejs'),
// YUI website API details.
YUI_API_HOST = 'stage.yuilibrary.com',
YUI_API_PORT = 80,
- YUI_API_ROOT = '/api/v1';
+ YUI_API_ROOT = '/api/v1',
+
+ getPath;
// First, make sure we have a version number.
if (!yuiVersion) {
@@ -47,19 +49,22 @@ if (!yuiVersion) {
process.exit(1);
}
+getPath = YUI_API_ROOT + '/classes/?sort=sortName&version=' +
+ encodeURIComponent(yuiVersion);
+
// Hit the YUI website API to get the latest syntax data.
console.log('Fetching latest syntax data from the YUI website API');
+console.log('http://' + YUI_API_HOST + getPath);
http.get({
host: YUI_API_HOST,
port: YUI_API_PORT,
- path: YUI_API_ROOT + '/classes/?sort=sortName&version=' +
- encodeURIComponent(yuiVersion)
+ path: getPath
}, function (res) {
var data = '';
if (res.statusCode < 200 || res.statusCode > 299) {
- onFetchError(Error('HTTP ' + res.statusCode));
+ onFetchError(new Error('HTTP ' + res.statusCode));
return;
}
@@ -69,6 +74,10 @@ http.get({
res.on('end', function () {
try {
data = JSON.parse(data);
+ if (!data.classes.length) {
+ onFetchError(new Error('No classes returned for version ' + yuiVersion));
+ return;
+ }
} catch (ex) {
onFetchError(ex);
return;
View
2  package.json
@@ -5,6 +5,6 @@
"author": "Ryan Grove <ryan@wonko.com>",
"dependencies": {
- "ejs": "~0.4.3"
+ "ejs": ">=0.4.3"
}
}
Something went wrong with that request. Please try again.