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/dayCountBasisLookup',
'services/NodeApi',
'Deal'
'Deal',
'services/HttpErrorHandler'
], (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);
let handleHttpFail = httpErrorHandler.createErrorHandler($scope);
$scope.dayCountBasisLookup = dayCountBasisLookup;
$scope.deal = nodeService.newDeal();
@ -17,7 +19,7 @@ define([
nodeService.createDeal(new Deal($scope.deal))
.then((tradeId) => $location.path('#/deal/' + tradeId), (resp) => {
$scope.formError = resp.data;
});
}, handleHttpFail);
};
$('input.percent').mask("9.999999%", {placeholder: "", autoclear: false});
$('#swapirscolumns').click(() => {

View File

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

View File

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

View File

@ -1,5 +1,7 @@
<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="http-error" ng-show="httpError">{{httpError}}</div>
<h3 class="ui horizontal divider header">
<i class="list icon"></i>
New Deal

View File

@ -1,5 +1,6 @@
<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 grid">
<div class="sixteen wide column" id="common">
<table class="ui striped table">

View File

@ -1,4 +1,5 @@
<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 info message" id="info-message" ng-show="infoMsg">{{infoMsg}}</div>
<div class="ui active dimmer" ng-show="isLoading()">