updated errors to actually show and error codes to be correct 401 rather than 403

This commit is contained in:
Solomon Laing 2020-02-14 21:25:45 +10:30
parent 261cb1ebb1
commit 18db5f47e8
2 changed files with 16 additions and 8 deletions

View File

@ -165,10 +165,11 @@ daddy.controller("createTopicCtrlr", function($scope, $location, $http, stateDat
$scope.createPost($scope.topic.postContent, res.data.topicNo) $scope.createPost($scope.topic.postContent, res.data.topicNo)
} }
}).catch((res) => { }).catch((res) => {
$scope.status.show = true;
if (res.status == 500) { if (res.status == 500) {
console.log("something went wrong: " + res.data) console.log("something went wrong: " + res.data)
$scope.status.text = "Something went wrong: " + res.status $scope.status.text = "Something went wrong: " + res.status
} else if (res.status == 403) { } else if (res.status == 401) {
console.log("something went worng: " + res.data) console.log("something went worng: " + res.data)
$scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again." $scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again."
stateData.logOut() stateData.logOut()
@ -196,10 +197,11 @@ daddy.controller("createTopicCtrlr", function($scope, $location, $http, stateDat
$location.path("/topics/" + topicNo) $location.path("/topics/" + topicNo)
} }
}).catch((res) => { }).catch((res) => {
$scope.status.show = true;
if (res.status == 500) { if (res.status == 500) {
console.log("something went wrong: " + res.data) console.log("something went wrong: " + res.data)
$scope.status.text = "Something went wrong: " + res.status $scope.status.text = "Something went wrong: " + res.status
} else if (res.status == 403) { } else if (res.status == 401) {
console.log("something went worng: " + res.data) console.log("something went worng: " + res.data)
$scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again." $scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again."
stateData.logOut() stateData.logOut()
@ -271,10 +273,11 @@ daddy.controller("createCategoryCtrlr", function($scope, $http, $location, state
$location.path("/categories/" + res.data.catNo) $location.path("/categories/" + res.data.catNo)
} }
}).catch((res) => { }).catch((res) => {
$scope.status.show = true;
if (res.status == 500) { if (res.status == 500) {
console.log("something went wrong: " + res.data) console.log("something went wrong: " + res.data)
$scope.status.text = "Something went wrong: " + res.status $scope.status.text = "Something went wrong: " + res.status
} else if (res.status == 403) { } else if (res.status == 401) {
console.log("something went worng: " + res.data) console.log("something went worng: " + res.data)
$scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again." $scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again."
stateData.logOut() stateData.logOut()
@ -360,11 +363,12 @@ daddy.controller("topicsCtrlr", function($scope, $routeParams, $timeout, $http,
$timeout(function() { $scope.getTopic() }, 2000) $timeout(function() { $scope.getTopic() }, 2000)
} }
}).catch((res) => { }).catch((res) => {
$scope.status.show = true;
if (res.status == 500) { if (res.status == 500) {
console.log("something went wrong: ") console.log("something went wrong: ")
console.log(res.data) console.log(res.data)
$scope.status.text = "Something went wrong: " + res.status $scope.status.text = "Something went wrong: " + res.status
} else if (res.status == 403) { } else if (res.status == 401) {
console.log("something went worng: " + res.data) console.log("something went worng: " + res.data)
$scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again." $scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again."
stateData.logOut() stateData.logOut()
@ -405,10 +409,11 @@ daddy.controller("topicsCtrlr", function($scope, $routeParams, $timeout, $http,
} }
}).catch((res) => { }).catch((res) => {
if (res.status == 500) { if (res.status == 500) {
$scope.status.show = true;
console.log("something went wrong: ") console.log("something went wrong: ")
console.log(res.data) console.log(res.data)
$scope.status.text = "Something went wrong: " + res.status $scope.status.text = "Something went wrong: " + res.status
} else if (res.status == 403) { } else if (res.status == 401) {
console.log("something went worng: " + res.data) console.log("something went worng: " + res.data)
$scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again." $scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again."
stateData.logOut() stateData.logOut()
@ -440,11 +445,12 @@ daddy.controller("topicsCtrlr", function($scope, $routeParams, $timeout, $http,
} }
} }
}).catch((res) => { }).catch((res) => {
$scope.status.show = true;
if (res.status == 500) { if (res.status == 500) {
console.log("something went wrong: ") console.log("something went wrong: ")
console.log(res.data) console.log(res.data)
$scope.status.text = "Something went wrong: " + res.status $scope.status.text = "Something went wrong: " + res.status
} else if (res.status == 403) { } else if (res.status == 401) {
console.log("something went worng: " + res.data) console.log("something went worng: " + res.data)
$scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again." $scope.status.text = "Authentication failed. For saftey reasons, you have been logged out, please log in and try again."
stateData.logOut() stateData.logOut()

View File

@ -30,11 +30,13 @@
<tr> <tr>
<td colspan="2" ng-show="state.user.userNo == null">{{logged.text1}} <span class="link" <td colspan="2" ng-show="state.user.userNo == null">{{logged.text1}} <span class="link"
ng-click="setLogin()">{{logged.link1}}</span> {{logged.text2}} <span class="link" ng-click="setLogin()">{{logged.link1}}</span> {{logged.text2}} <span class="link"
ng-click="setSignup()">{{logged.link2}}</span> {{logged.text3}}</td> ng-click="setSignup()">{{logged.link2}}</span> {{logged.text3}}
<p class="status" ng-show="status.show">{{status.text}}</p>
</td>
<td colspan="2" ng-show="state.user.userNo != null"> <td colspan="2" ng-show="state.user.userNo != null">
<form name="replyForm" id="replyForm" ng-submit="makeReply(topic.topicNo)"> <form name="replyForm" id="replyForm" ng-submit="makeReply(topic.topicNo)">
<label for="replyCotnent">Reply:</label> <br /> <label for="replyCotnent">Reply:</label> <br />
<textarea name="replyContent" ng-model="reply.postContent" required></textarea> <br /> <textarea name="replyContent" ng-model="reply.postContent" required></textarea> <br />
<input type="submit" name="replySubmit" ng-model="reply.submit" value="Reply" /> <input type="submit" name="replySubmit" ng-model="reply.submit" value="Reply" />
</form> </form>
<p class="status" ng-show="status.show">{{status.text}}</p> <p class="status" ng-show="status.show">{{status.text}}</p>