mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:15:50 +00:00
add simple error handler for OwnerController.js
This commit is contained in:
parent
080f9e4142
commit
7c131fd4dc
1 changed files with 30 additions and 20 deletions
|
@ -65,16 +65,26 @@ function($scope, $http, $resource, $stateParams, $state) {
|
||||||
telephone: form.telephone
|
telephone: form.telephone
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var request;
|
||||||
|
|
||||||
if ($state.current.name == 'app.owneredit') {
|
if ($state.current.name == 'app.owneredit') {
|
||||||
var restUrl = "/petclinic/owner/" + $stateParams.id;
|
var restUrl = "/petclinic/owner/" + $stateParams.id;
|
||||||
$http.put(restUrl, data);
|
request = $http.put(restUrl, data);
|
||||||
$state.go('app.ownerlist');
|
|
||||||
}
|
}
|
||||||
else { // in case of owner creation
|
else { // in case of owner creation
|
||||||
var restUrl = "/petclinic/owner";
|
var restUrl = "/petclinic/owner";
|
||||||
$http.post(restUrl, data);
|
request = $http.post(restUrl, data);
|
||||||
$state.go('app.ownerlist');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
request.then(function () {
|
||||||
|
$state.go('app.ownerlist');
|
||||||
|
}, function (response) {
|
||||||
|
var error = response.data;
|
||||||
|
alert(error.error + "\r\n" + error.errors.map(function (e) {
|
||||||
|
return e.field + ": " + e.defaultMessage;
|
||||||
|
}).join("\r\n"));
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($state.current.name == 'app.owneredit') {
|
if ($state.current.name == 'app.owneredit') {
|
||||||
|
|
Loading…
Reference in a new issue