Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #278 from Wikia/XW-4301
Browse files Browse the repository at this point in the history
XW-3360 | User-friendly message for 403
  • Loading branch information
Aga Serowiec authored Nov 27, 2017
2 parents 456e88f + 70e2131 commit fbc4aa8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
10 changes: 10 additions & 0 deletions app/controllers/application-error.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Controller from '@ember/controller';
import {computed} from '@ember/object';
import {getProductionErrorMessage, canAttemptRefresh} from '../utils/errors';

export default Controller.extend({
additionalData: computed(function () {
Expand All @@ -13,5 +14,14 @@ export default Controller.extend({
.replace(new RegExp('\\n', 'g'), '<br />');

return stackTrace ? stackTrace : 'No stack trace available';
}),

productionErrorContext: computed(function () {
const errorCode = this.get('controller.model.error.code');

return {
message: getProductionErrorMessage(errorCode),
canAttemptRefresh: canAttemptRefresh(errorCode)
};
})
});
6 changes: 4 additions & 2 deletions app/templates/errors/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
</div>
<div class="show-error-container">
<h1>Error</h1>
<div>Sorry, we couldn't load the page. Please try again.</div>
<button class="wds-button" onclick="window.location.reload()">Refresh</button>
<div>{{productionErrorContext.message}}</div>
{{#if productionErrorContext.canAttemptRefresh}}
<button class="wds-button" onclick="window.location.reload()">Refresh</button>
{{/if}}
</div>
15 changes: 15 additions & 0 deletions app/utils/errors.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import {defineError} from 'ember-exex/error';

const errorsMap = {
403: 'You do not have permissions to view this page.',
default: 'Sorry, we couldn\'t load the page. Please try again.'
};

const DesignSystemFetchError = defineError({
name: 'DesignSystemFetchError',
message: `Design System data couldn't be fetched`
Expand Down Expand Up @@ -56,6 +61,14 @@ const getFetchErrorMessage = function (response) {
}
};

const canAttemptRefresh = function (errorCode) {
return typeof errorCode === 'number' && errorCode >= 500;
};

const getProductionErrorMessage = function (errorCode) {
return errorsMap[errorCode] || errorsMap.default;
};

export {
getFetchErrorMessage,
DesignSystemFetchError,
Expand All @@ -67,4 +80,6 @@ export {
TrackingDimensionsFetchError,
WikiPageFetchError,
WikiVariablesFetchError,
canAttemptRefresh,
getProductionErrorMessage
};

0 comments on commit fbc4aa8

Please sign in to comment.