Added more errror handling for the IRS demo

This commit is contained in:
Clinton Alexander 2017-05-04 16:05:44 +01:00 committed by Clinton Alexander
parent 48bded2ec3
commit f45c3cc214
8 changed files with 36 additions and 15 deletions

View File

@ -6,10 +6,12 @@ define([
'utils/semantic', 'utils/semantic',
'utils/dayCountBasisLookup', 'utils/dayCountBasisLookup',
'services/NodeApi', 'services/NodeApi',
'Deal' 'Deal',
'services/HttpErrorHandler'
], (angular, maskedInput, semantic, dayCountBasisLookup, nodeApi, Deal) => { ], (angular, maskedInput, semantic, dayCountBasisLookup, nodeApi, Deal) => {
angular.module('irsViewer').controller('CreateDealController', function CreateDealController($http, $scope, $location, nodeService) { angular.module('irsViewer').controller('CreateDealController', function CreateDealController($http, $scope, $location, nodeService, httpErrorHandler) {
semantic.init($scope, nodeService.isLoading); semantic.init($scope, nodeService.isLoading);
let handleHttpFail = httpErrorHandler.createErrorHandler($scope);
$scope.dayCountBasisLookup = dayCountBasisLookup; $scope.dayCountBasisLookup = dayCountBasisLookup;
$scope.deal = nodeService.newDeal(); $scope.deal = nodeService.newDeal();
@ -17,7 +19,7 @@ define([
nodeService.createDeal(new Deal($scope.deal)) nodeService.createDeal(new Deal($scope.deal))
.then((tradeId) => $location.path('#/deal/' + tradeId), (resp) => { .then((tradeId) => $location.path('#/deal/' + tradeId), (resp) => {
$scope.formError = resp.data; $scope.formError = resp.data;
}); }, handleHttpFail);
}; };
$('input.percent').mask("9.999999%", {placeholder: "", autoclear: false}); $('input.percent').mask("9.999999%", {placeholder: "", autoclear: false});
$('#swapirscolumns').click(() => { $('#swapirscolumns').click(() => {

View File

@ -1,9 +1,9 @@
'use strict'; 'use strict';
define(['angular', 'utils/semantic', 'services/NodeApi'], (angular, semantic, nodeApi) => { define(['angular', 'utils/semantic', 'services/NodeApi', 'services/HttpErrorHandler'], (angular, semantic) => {
angular.module('irsViewer').controller('DealController', function DealController($http, $scope, $routeParams, nodeService) { angular.module('irsViewer').controller('DealController', function DealController($http, $scope, $routeParams, nodeService, httpErrorHandler) {
semantic.init($scope, nodeService.isLoading); semantic.init($scope, nodeService.isLoading);
let handleHttpFail = httpErrorHandler.createErrorHandler($scope);
nodeService.getDeal($routeParams.dealId).then((deal) => $scope.deal = deal); nodeService.getDeal($routeParams.dealId).then((deal) => $scope.deal = deal, handleHttpFail);
}); });
}); });

View File

@ -1,12 +1,10 @@
'use strict'; 'use strict';
define(['angular', 'utils/semantic', 'services/NodeApi'], (angular, semantic, nodeApi) => { define(['angular', 'utils/semantic', 'services/NodeApi', 'services/HttpErrorHandler'], (angular, semantic) => {
angular.module('irsViewer').controller('HomeController', function HomeController($http, $scope, nodeService) { angular.module('irsViewer').controller('HomeController', function HomeController($http, $scope, nodeService, httpErrorHandler) {
semantic.addLoadingModal($scope, nodeService.isLoading); semantic.addLoadingModal($scope, nodeService.isLoading);
let handleHttpFail = (resp) => { let handleHttpFail = httpErrorHandler.createErrorHandler($scope);
$scope.httpError = resp.data
};
$scope.infoMsg = ""; $scope.infoMsg = "";
$scope.errorText = ""; $scope.errorText = "";
@ -28,7 +26,7 @@ define(['angular', 'utils/semantic', 'services/NodeApi'], (angular, semantic, no
return name; return name;
}; };
nodeService.getDate().then((date) => $scope.date = date); nodeService.getDate().then((date) => $scope.date = date, handleHttpFail);
nodeService.getDeals().then((deals) => $scope.deals = deals); nodeService.getDeals().then((deals) => $scope.deals = deals, handleHttpFail);
}); });
}); });

View File

@ -0,0 +1,17 @@
'use strict';
define(['angular', 'lodash', 'viewmodel/Deal'], (angular, _) => {
angular.module('irsViewer').factory('httpErrorHandler', () => {
return {
createErrorHandler: (scope) => {
return (resp) => {
if(resp.status == -1) {
scope.httpError = "Could not connect to node web server";
} else {
scope.httpError = resp.data;
}
};
}
};
});
});

View File

@ -5,7 +5,7 @@ define(['angular', 'lodash', 'viewmodel/Deal'], (angular, _, dealViewModel) => {
return new (function() { return new (function() {
let date = new Date(2016, 0, 1, 0, 0, 0); let date = new Date(2016, 0, 1, 0, 0, 0);
let curLoading = {}; let curLoading = {};
let serverAddr = ''; // Leave empty to target the same host this page is served from let serverAddr = 'http://localhost:10007'; // Leave empty to target the same host this page is served from
let load = (type, promise) => { let load = (type, promise) => {
curLoading[type] = true; curLoading[type] = true;

View File

@ -1,5 +1,7 @@
<div class="ui container"> <div class="ui container">
<div class="ui hidden divider"></div>
<div class="ui negative message" id="form-error" ng-show="formError">{{formError}}</div> <div class="ui negative message" id="form-error" ng-show="formError">{{formError}}</div>
<div class="ui negative message" id="http-error" ng-show="httpError">{{httpError}}</div>
<h3 class="ui horizontal divider header"> <h3 class="ui horizontal divider header">
<i class="list icon"></i> <i class="list icon"></i>
New Deal New Deal

View File

@ -1,5 +1,6 @@
<div class="ui container"> <div class="ui container">
<div class="ui hidden divider"></div> <div class="ui hidden divider"></div>
<div class="ui negative message" id="http-error" ng-show="httpError">{{httpError}}</div>
<div class="ui grid"> <div class="ui grid">
<div class="sixteen wide column" id="common"> <div class="sixteen wide column" id="common">
<table class="ui striped table"> <table class="ui striped table">

View File

@ -1,4 +1,5 @@
<div class="ui container"> <div class="ui container">
<div class="ui hidden divider"></div>
<div class="ui negative message" id="http-error" ng-show="httpError">{{httpError}}</div> <div class="ui negative message" id="http-error" ng-show="httpError">{{httpError}}</div>
<div class="ui info message" id="info-message" ng-show="infoMsg">{{infoMsg}}</div> <div class="ui info message" id="info-message" ng-show="infoMsg">{{infoMsg}}</div>
<div class="ui active dimmer" ng-show="isLoading()"> <div class="ui active dimmer" ng-show="isLoading()">