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

fix(core): Add custom 400 and 404 error messages #1510

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions modules/core/client/config/core.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,31 @@
.state('not-found', {
url: '/not-found',
templateUrl: 'modules/core/client/views/404.client.view.html',
controller: 'ErrorController',
controllerAs: 'vm',
params: {
message: function($stateParams) {
return $stateParams.message;
}
},
data: {
ignoreState: true,
pageTitle: 'Not-Found'
pageTitle: 'Not Found'
}
})
.state('bad-request', {
url: '/bad-request',
templateUrl: 'modules/core/client/views/400.client.view.html',
controller: 'ErrorController',
controllerAs: 'vm',
params: {
message: function($stateParams) {
return $stateParams.message;
}
},
data: {
ignoreState: true,
pageTitle: 'Bad-Request'
pageTitle: 'Bad Request'
}
})
.state('forbidden', {
Expand Down
18 changes: 18 additions & 0 deletions modules/core/client/controllers/error.client.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function () {
'use strict';

angular
.module('core')
.controller('ErrorController', ErrorController);

ErrorController.$inject = ['$stateParams'];

function ErrorController($stateParams) {
var vm = this;
vm.errorMessage = null;

// Display custom message if it was set
if ($stateParams.message) vm.errorMessage = $stateParams.message;
}
}());

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
function responseError(rejection) {
if (!rejection.config.ignoreAuthModule) {
switch (rejection.status) {
case 400:
$injector.get('$state').go('bad-request', { message: rejection.data.message });
break;
case 401:
// Deauthenticate the global user
Authentication.user = null;
Expand All @@ -25,6 +28,9 @@
case 403:
$injector.get('$state').transitionTo('forbidden');
break;
case 404:
$injector.get('$state').go('not-found', { message: rejection.data.message });
break;
}
}
// otherwise, default behaviour
Expand Down
7 changes: 5 additions & 2 deletions modules/core/client/views/400.client.view.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<h1>Bad Request</h1>
<div class="page-header">
<h1>Bad Request</h1>
</div>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
You made a bad request
<span ng-if="vm.errorMessage" ng-bind="vm.errorMessage"></span>
<span ng-if="!vm.errorMessage">You made a bad request</span>
</div>
4 changes: 3 additions & 1 deletion modules/core/client/views/403.client.view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<h1>Forbidden</h1>
<div class="page-header">
<h1>Forbidden</h1>
</div>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>
Expand Down
7 changes: 5 additions & 2 deletions modules/core/client/views/404.client.view.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<h1>Page Not Found</h1>
<div class="page-header">
<h1>Page Not Found</h1>
</div>
<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span> Page Not Found
<span ng-if="vm.errorMessage" ng-bind="vm.errorMessage"></span>
<span ng-if="!vm.errorMessage">Page Not Found</span>
</div>