Permalink
Browse files

Merge pull request #424 from nodejitsu/421

[ux] Notify user if the application doesn't exist LGTM
  • Loading branch information...
2 parents 5576b0a + 5995f30 commit f7fff4c237cc9f954ce2af47c45112fe829efb73 @Swaagie Swaagie committed Mar 26, 2013
Showing with 30 additions and 5 deletions.
  1. +13 −5 lib/jitsu/commands/logs.js
  2. +17 −0 test/commands/logs-test.js
View
@@ -103,14 +103,22 @@ logs.app = function (appName, amount, callback) {
}
function byApp(appName, amount, callback) {
- jitsu.logs.byApp(appName, amount, function (err, results) {
+ jitsu.apps.view(appName, function (err) {
if (err) {
- return callback(err);
+ return err.statusCode === 404
+ ? callback(new Error('Application not found.'), true)
+ : callback(err);
}
- jitsu.log.info('Listing logs for ' + appName.magenta);
- putLogs(results, appName, amount);
- callback();
+ jitsu.logs.byApp(appName, amount, function (err, results) {
+ if (err) {
+ return callback(err);
+ }
+
+ jitsu.log.info('Listing logs for ' + appName.magenta);
+ putLogs(results, appName, amount);
+ callback();
+ });
});
}
View
@@ -23,13 +23,18 @@ var fixturesDir = path.join(__dirname, '..', 'fixtures'),
loggedOutFile = path.join(fixturesDir, 'logged-out-jitsuconf')
loggedOutConf = fs.readFileSync(loggedOutFile, 'utf8');
+var exampleApp = { app: { _id: 'tester/example-app', config: { cloud: [] } } },
+ application = { app: { _id: 'tester/application', config: { cloud: [] } } };
+
// Snapshots tests with specified app names
vows.describe('jitsu/commands/logs').addBatch({
'logs': shouldNodejitsuOk(function setup() {
useAppFixture();
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/example-app')
+ .reply(200, exampleApp, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/example-app', {
from: "NOW-1DAY",
until: "NOW",
@@ -101,6 +106,8 @@ vows.describe('jitsu/commands/logs').addBatch({
jitsu.prompt.override.password = 'EXAMPLE-PASSWORD';
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/example-app')
+ .reply(200, exampleApp, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/example-app', {
from: "NOW-1DAY",
until: "NOW",
@@ -166,6 +173,8 @@ vows.describe('jitsu/commands/logs').addBatch({
useAppFixture();
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/example-app')
+ .reply(200, exampleApp, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/example-app', {
from: "NOW-1DAY",
until: "NOW",
@@ -237,6 +246,8 @@ vows.describe('jitsu/commands/logs').addBatch({
jitsu.prompt.override.password = 'EXAMPLE-PASSWORD';
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/example-app')
+ .reply(200, exampleApp, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/example-app', {
from: "NOW-1DAY",
until: "NOW",
@@ -300,6 +311,8 @@ vows.describe('jitsu/commands/logs').addBatch({
'logs app application': shouldNodejitsuOk(function setup() {
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/application')
+ .reply(200, application, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/application', {
from: "NOW-1DAY",
until: "NOW",
@@ -366,6 +379,8 @@ vows.describe('jitsu/commands/logs').addBatch({
jitsu.prompt.override.password = 'EXAMPLE-PASSWORD';
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/application')
+ .reply(200, application, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/application', {
from: "NOW-1DAY",
until: "NOW",
@@ -426,6 +441,8 @@ vows.describe('jitsu/commands/logs').addBatch({
'logs app application 10': shouldNodejitsuOk(function setup() {
nock('https://api.mockjitsu.com')
+ .get('/apps/tester/application')
+ .reply(200, application, { 'x-powered-by': 'Nodejitsu' })
.post('/logs/tester/application', {
from: "NOW-1DAY",
until: "NOW",

0 comments on commit f7fff4c

Please sign in to comment.