From 8265cb5705f44cdad9db3e17432821e3777de450 Mon Sep 17 00:00:00 2001 From: Michael Aufreiter Date: Sat, 23 Jun 2012 02:11:50 -0400 Subject: [PATCH] Better error handling. Closes #113. --- _includes/model.js | 2 +- _includes/routers/application.js | 1 + _includes/views/application.js | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/_includes/model.js b/_includes/model.js index 0850c32b9..6ae086165 100644 --- a/_includes/model.js +++ b/_includes/model.js @@ -156,7 +156,7 @@ function loadSite(user, repo, branch, path, cb) { repo.getSha(branch, path, function(err, sha) { repo.getTree(sha, function(err, tree) { - if (err) cb("Not a valid Jekyll repository."); + if (err) return cb("Not found"); var paths = _.compact(_.map(tree, function(file) { return file.type === "tree" ? (path ? path + "/" : "")+ file.path : null; diff --git a/_includes/routers/application.js b/_includes/routers/application.js index 5d699e389..1183e829f 100644 --- a/_includes/routers/application.js +++ b/_includes/routers/application.js @@ -48,6 +48,7 @@ routers.Application = Backbone.Router.extend({ // #example-user/example-repo/gh-pages/path/to // #example-user/example-repo/gh-pages posts: function(url) { + if (url.split('/').length < 3) return app.instance.notify('error', 'Not Found'); if (confirmExit()) { app.instance.posts.apply(this, this.extractURL(url)); } diff --git a/_includes/views/application.js b/_includes/views/application.js index eed166294..86a9fde8e 100644 --- a/_includes/views/application.js +++ b/_includes/views/application.js @@ -70,7 +70,7 @@ views.Application = Backbone.View.extend({ posts: function (user, repo, branch, path) { loadSite(user, repo, branch, path, _.bind(function (err, data) { - if (err) return this.notify('error', 'Seems like the chosen repository is not a valid Jekyll site.'); + if (err) return this.notify('error', 'The requested resource could not be found.'); this.header.render(); this.replaceMainView("posts", new views.Posts({ model: data, id: 'posts' }).render()); }, this)); @@ -78,8 +78,8 @@ views.Application = Backbone.View.extend({ post: function (user, repo, branch, path, file, preview) { loadSite(user, repo, branch, path, _.bind(function (err, data) { - - if (err) return this.notify('error', 'Seems like the chosen repository is not a valid Jekyll site.'); + + if (err) return this.notify('error', 'The requested resource could not be found.'); loadPost(user, repo, branch, path, file, _.bind(function (err, data) { data.preview = preview; this.header.render();