Updated scope API for error handling
parent
18e319379e
commit
435fff3b1c
|
@ -18,7 +18,6 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
@ -123,7 +122,7 @@ public class ScopeAPI {
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
logger.error("There was an error attempting to save scope: " + scope + " : " + e.getStackTrace().toString());
|
logger.error("There was an error attempting to save scope: " + scope + " : " + e.getStackTrace().toString());
|
||||||
m.put("code", HttpStatus.BAD_REQUEST);
|
m.put("code", HttpStatus.BAD_REQUEST);
|
||||||
m.put("entity", "An error occurred while processing your request");
|
m.put("entity", "An error occurred while processing your request.");
|
||||||
return "jsonEntityView";
|
return "jsonEntityView";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,9 +134,10 @@ public class ScopeAPI {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
logger.error("createScope failed; JSON was invalid: " + json);
|
logger.error("createScope failed; JSON was invalid: " + json);
|
||||||
|
m.put("entity", "An error occurred while processing your request - invalud JSON.");
|
||||||
m.put("code", HttpStatus.BAD_REQUEST);
|
m.put("code", HttpStatus.BAD_REQUEST);
|
||||||
|
|
||||||
return "httpCodeView";
|
return "jsonEntityView";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,10 +84,13 @@ var SystemScopeView = Backbone.View.extend({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
error:function () {
|
error:function (error, response) {
|
||||||
|
|
||||||
|
//Pull out the response text.
|
||||||
|
var responseText = JSON.parse(response.responseText);
|
||||||
|
|
||||||
//Display an alert with an error message
|
//Display an alert with an error message
|
||||||
$('#modalAlert div.modal-body').html("<div class='alert alert-error'><strong>Warning!</strong> An error occurred when processing your request. Please refresh the page and try again.</div>");
|
$('#modalAlert div.modal-body').html("<div class='alert alert-error'><strong>Warning!</strong>" + responseText + "</div>");
|
||||||
|
|
||||||
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
|
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
|
||||||
"backdrop" : "static",
|
"backdrop" : "static",
|
||||||
|
@ -236,10 +239,14 @@ var SystemScopeFormView = Backbone.View.extend({
|
||||||
app.navigate('admin/scope', {trigger: true});
|
app.navigate('admin/scope', {trigger: true});
|
||||||
},
|
},
|
||||||
error:function(error, response) {
|
error:function(error, response) {
|
||||||
if (response.status == 409) {
|
|
||||||
|
//Pull out the response text.
|
||||||
|
var responseText = JSON.parse(response.responseText);
|
||||||
|
|
||||||
|
if (response.status == 409) {
|
||||||
//Conflict, scope already exists
|
//Conflict, scope already exists
|
||||||
$('#value.control-group input').addClass('inputError');
|
$('#value.control-group input').addClass('inputError');
|
||||||
$('#value.control-group').before('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>A scope with this value already exists, please choose a different value.</div>');
|
$('#value.control-group').before('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>' + responseText + '</div>');
|
||||||
|
|
||||||
$('#value.control-group').bind('click.error', function() {
|
$('#value.control-group').bind('click.error', function() {
|
||||||
$('#value.control-group input').removeClass('inputError');
|
$('#value.control-group input').removeClass('inputError');
|
||||||
|
@ -248,9 +255,14 @@ var SystemScopeFormView = Backbone.View.extend({
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//TODO: if there are any other known error cases, catch those by response status and display
|
//Display an alert with an error message
|
||||||
//appropriate messages.
|
$('#modalAlert div.modal-body').html("<div class='alert alert-error'><strong>Warning!</strong>" + responseText + "</div>");
|
||||||
$('#value.control-group').before('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>A system error occurred when processing your request.</div>');
|
|
||||||
|
$("#modalAlert").modal({ // wire up the actual modal functionality and show the dialog
|
||||||
|
"backdrop" : "static",
|
||||||
|
"keyboard" : true,
|
||||||
|
"show" : true // ensure the modal is shown immediately
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue