diff --git a/app/router.js b/app/router.js index fdef4198c..31184d06c 100644 --- a/app/router.js +++ b/app/router.js @@ -20,7 +20,9 @@ const Router = Ember.Router.extend({ }); Router.map(function() { + this.route('404'); this.route('project', {path: '/:project'}); + this.route('project-version', {path: '/:project/:project_version'}, function() { // this.route('classes-redirect', {path: '/classes'}); diff --git a/app/routes/application.js b/app/routes/application.js index afd0691a0..b98ece43a 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -5,6 +5,7 @@ const { set, inject } = Ember; export default Ember.Route.extend({ headData: inject.service(), + title(tokens) { const reversed = Ember.makeArray(tokens).reverse(); const title = `${reversed.join(' - ')} - Ember API Documentation`; @@ -12,4 +13,5 @@ export default Ember.Route.extend({ set(this, 'headData.cdnDomain', ENV.API_HOST); return title; } + }); diff --git a/app/routes/project-version/classes/class.js b/app/routes/project-version/classes/class.js index 729349774..2f21e47b1 100644 --- a/app/routes/project-version/classes/class.js +++ b/app/routes/project-version/classes/class.js @@ -25,20 +25,27 @@ export default Ember.Route.extend(ScrollTracker, { find(typeName, param) { return this.store.find(typeName, param).catch(() => { return this.store.find('namespace', param).catch(() => { - return this.transitionTo('project-version'); // class doesn't exist in new version + return Ember.RSVP.resolve({ isError: true }); }); }); }, + redirect(model, transition) { + if (model.isError) { + this.transitionTo('404'); + } + }, + afterModel(klass) { - set(this, 'headData.description', klass.get('ogDescription')); - const relationships = get(klass.constructor, 'relationshipNames'); - const promises = Object.keys(relationships).reduce((memo, relationshipType) => { - const relationshipPromises = relationships[relationshipType].map(name => klass.get(name)); - return memo.concat(relationshipPromises); - }, []); - - return Ember.RSVP.all(promises); + if (!klass.isError) { + set(this, 'headData.description', klass.get('ogDescription')); + const relationships = get(klass.constructor, 'relationshipNames'); + const promises = Object.keys(relationships).reduce((memo, relationshipType) => { + const relationshipPromises = relationships[relationshipType].map(name => klass.get(name)); + return memo.concat(relationshipPromises); + }, []); + return Ember.RSVP.all(promises); + } }, serialize(model) { diff --git a/app/templates/404.hbs b/app/templates/404.hbs new file mode 100644 index 000000000..18fc74ad1 --- /dev/null +++ b/app/templates/404.hbs @@ -0,0 +1,10 @@ +
+

+

Ack! 404 friend, you're in the wrong place

+
+

+ This page wasn't found. Please try the {{#link-to 'index'}}API docs page{{/link-to}}. + If you expected something else to be here, please file a ticket. +

+
+