From a6e3f704e58df410449e471cd35ce79b976799c0 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 10 Mar 2017 17:36:48 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20oauth2-ghost=20authenticat?= =?UTF-8?q?or=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - updates `oauth2-ghost` authenticator to reflect the fact that `makeRequest` now returns a ember-ajax and matches the `oauth2` authenticator behaviour - handle `UnauthorizedError` errors in application route's error handler to avoid tests breaking from unhandled exceptions --- ghost/admin/app/authenticators/oauth2-ghost.js | 4 ++-- ghost/admin/app/routes/application.js | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ghost/admin/app/authenticators/oauth2-ghost.js b/ghost/admin/app/authenticators/oauth2-ghost.js index 83a3eb62c2..fcb9eed2c1 100644 --- a/ghost/admin/app/authenticators/oauth2-ghost.js +++ b/ghost/admin/app/authenticators/oauth2-ghost.js @@ -32,8 +32,8 @@ export default Oauth2Authenticator.extend({ } resolve(response); }); - }, (xhr) => { - run(null, reject, xhr.responseJSON || xhr.responseText); + }, (error) => { + reject(error); }); }); } diff --git a/ghost/admin/app/routes/application.js b/ghost/admin/app/routes/application.js index 60a35eb6bb..ca66c93bc4 100644 --- a/ghost/admin/app/routes/application.js +++ b/ghost/admin/app/routes/application.js @@ -5,7 +5,7 @@ import run from 'ember-runloop'; import {isEmberArray} from 'ember-array/utils'; import observer from 'ember-metal/observer'; import $ from 'jquery'; - +import {isUnauthorizedError} from 'ember-ajax/errors'; import AuthConfiguration from 'ember-simple-auth/configuration'; import ApplicationRouteMixin from 'ember-simple-auth/mixins/application-route-mixin'; import ShortcutsRoute from 'ghost-admin/mixins/shortcuts-route'; @@ -195,6 +195,11 @@ export default Route.extend(ApplicationRouteMixin, ShortcutsRoute, { save: K, error(error, transition) { + // unauthoirized errors are already handled in the ajax service + if (isUnauthorizedError(error)) { + return false; + } + if (error && isEmberArray(error.errors)) { switch (error.errors[0].errorType) { case 'NotFoundError': {