From e36c0966d05169cdc49154cbff5385f419f5d866 Mon Sep 17 00:00:00 2001 From: Kane York Date: Mon, 21 Sep 2015 11:33:21 -0700 Subject: [PATCH] FIX: :( page was never showing the URL --- .../discourse/controllers/exception.js.es6 | 5 ++++ .../discourse/routes/application.js.es6 | 24 +++++++------------ config/locales/client.en.yml | 2 ++ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/exception.js.es6 b/app/assets/javascripts/discourse/controllers/exception.js.es6 index b2ff890eea0..2adcff6c0fe 100644 --- a/app/assets/javascripts/discourse/controllers/exception.js.es6 +++ b/app/assets/javascripts/discourse/controllers/exception.js.es6 @@ -31,6 +31,7 @@ export default Ember.Controller.extend({ if (this.get('thrown.jqTextStatus') === "timeout") return true; return false; }.property(), + isNotFound: Em.computed.equal('thrown.status', 404), isForbidden: Em.computed.equal('thrown.status', 403), isServer: Em.computed.gte('thrown.status', 500), isUnknown: Em.computed.none('isNetwork', 'isServer'), @@ -50,6 +51,8 @@ export default Ember.Controller.extend({ return I18n.t('errors.reasons.network'); } else if (this.get('isServer')) { return I18n.t('errors.reasons.server'); + } else if (this.get('isNotFound')) { + return I18n.t('errors.reasons.not_found'); } else if (this.get('isForbidden')) { return I18n.t('errors.reasons.forbidden'); } else { @@ -65,6 +68,8 @@ export default Ember.Controller.extend({ return I18n.t('errors.desc.network_fixed'); } else if (this.get('isNetwork')) { return I18n.t('errors.desc.network'); + } else if (this.get('isNotFound')) { + return I18n.t('errors.desc.not_found'); } else if (this.get('isServer')) { return I18n.t('errors.desc.server', { status: this.get('thrown.status') + " " + this.get('thrown.statusText') }); } else { diff --git a/app/assets/javascripts/discourse/routes/application.js.es6 b/app/assets/javascripts/discourse/routes/application.js.es6 index 17023a74aab..e3280b18206 100644 --- a/app/assets/javascripts/discourse/routes/application.js.es6 +++ b/app/assets/javascripts/discourse/routes/application.js.es6 @@ -60,30 +60,24 @@ const ApplicationRoute = Discourse.Route.extend(OpenComposer, { }, error(err, transition) { - if (err.status === 404) { - // 404 - this.transitionTo('unknown'); - return; + let xhr = {}; + if (err.jqXHR) { + xhr = err.jqXHR; } - const exceptionController = this.controllerFor('exception'), - stack = err.stack; + const xhrOrErr = err.jqXHR ? xhr : err; - // If we have a stack call `toString` on it. It gives us a better - // stack trace since `console.error` uses the stack track of this - // error callback rather than the original error. - let errorString = err.toString(); - if (stack) { errorString = stack.toString(); } - - if (err.statusText) { errorString = err.statusText; } + const exceptionController = this.controllerFor('exception'); const c = window.console; if (c && c.error) { - c.error(errorString); + c.error(xhrOrErr); } - exceptionController.setProperties({ lastTransition: transition, thrown: err }); + + exceptionController.setProperties({ lastTransition: transition, thrown: xhrOrErr }); this.intermediateTransitionTo('exception'); + return true; }, showLogin: unlessReadOnly('handleShowLogin'), diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 0e9ca3d2f0d..4dd0b0cf5c7 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -684,11 +684,13 @@ en: server: "Server Error" forbidden: "Access Denied" unknown: "Error" + not_found: "Page Not Found" desc: network: "Please check your connection." network_fixed: "Looks like it's back." server: "Error code: {{status}}" forbidden: "You're not allowed to view that." + not_found: "Oops, the application tried to load a URL that doesn't exist." unknown: "Something went wrong." buttons: back: "Go Back"