mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Merge pull request #6506 from acburdine/posts-error-fix
Improve 404 error handling in post route
This commit is contained in:
commit
507adb7fc1
@ -1,9 +1,10 @@
|
|||||||
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
import AuthenticatedRoute from 'ghost/routes/authenticated';
|
||||||
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
import ShortcutsRoute from 'ghost/mixins/shortcuts-route';
|
||||||
|
import NotFoundHandler from 'ghost/mixins/404-handler';
|
||||||
import isNumber from 'ghost/utils/isNumber';
|
import isNumber from 'ghost/utils/isNumber';
|
||||||
import isFinite from 'ghost/utils/isFinite';
|
import isFinite from 'ghost/utils/isFinite';
|
||||||
|
|
||||||
export default AuthenticatedRoute.extend(ShortcutsRoute, {
|
export default AuthenticatedRoute.extend(ShortcutsRoute, NotFoundHandler, {
|
||||||
model(params) {
|
model(params) {
|
||||||
let post,
|
let post,
|
||||||
postId,
|
postId,
|
||||||
@ -28,14 +29,14 @@ export default AuthenticatedRoute.extend(ShortcutsRoute, {
|
|||||||
staticPages: 'all'
|
staticPages: 'all'
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.store.queryRecord('post', query).then((records) => {
|
return this.store.query('post', query).then((records) => {
|
||||||
let post = records.get('firstObject');
|
let post = records.get('firstObject');
|
||||||
|
|
||||||
if (post) {
|
if (post) {
|
||||||
return post;
|
return post;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.transitionTo('error404', postId);
|
return this.replaceWith('posts.index');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ import startApp from '../../helpers/start-app';
|
|||||||
import destroyApp from '../../helpers/destroy-app';
|
import destroyApp from '../../helpers/destroy-app';
|
||||||
import { invalidateSession, authenticateSession } from 'ghost/tests/helpers/ember-simple-auth';
|
import { invalidateSession, authenticateSession } from 'ghost/tests/helpers/ember-simple-auth';
|
||||||
import { errorOverride, errorReset } from 'ghost/tests/helpers/adapter-error';
|
import { errorOverride, errorReset } from 'ghost/tests/helpers/adapter-error';
|
||||||
|
import Mirage from 'ember-cli-mirage';
|
||||||
|
|
||||||
describe('Acceptance: Posts - Post', function() {
|
describe('Acceptance: Posts - Post', function() {
|
||||||
let application;
|
let application;
|
||||||
@ -51,17 +52,19 @@ describe('Acceptance: Posts - Post', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with 404', function () {
|
it('redirects to 404 when post does not exist', function () {
|
||||||
it('redirects to 404 when post does not exist', function () {
|
server.get('/posts/200/', function () {
|
||||||
let posts = server.createList('post', 3);
|
return new Mirage.Response(404, {'Content-Type': 'application/json'}, {errors: [{message: 'Post not found.', errorType: 'NotFoundError'}]});
|
||||||
|
});
|
||||||
|
|
||||||
visit('/4');
|
errorOverride();
|
||||||
|
|
||||||
andThen(() => {
|
visit('/200');
|
||||||
// it redirects to 404 error page
|
|
||||||
expect(currentPath()).to.equal('error404');
|
andThen(() => {
|
||||||
expect(currentURL()).to.equal('/4');
|
errorReset();
|
||||||
});
|
expect(currentPath()).to.equal('error404');
|
||||||
|
expect(currentURL()).to.equal('/200');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user