I have a controller that throws an exception as an example:
[HttpPost]
public JsonResult RetrieveTransactionStatuses() {
throw new Exception("Test exceptioN");
return this.Json(this.RetrieveStatusLines());
}
I am calling the above using the angular script:
$http.post('/Status/RetrieveTransactionStatuses')
.then(function (response) {
// success
console.log('on success');
vm.statusLines = response.data;
},
function () {
// failure
console.log('on failure');
ExceptionHandlers.Methods.ShowError('Error Retrieving Data!', 'There has been an error retrieving the status data');
});
However, the above method in the controller, will return a page with a 200 OK status. Is there a way to differentiate POST Methods and then have it return a proper HTTP error status code (500)?
Essentially, after the error on a post method, I will popup a warning in a dialog to notify that an error has occurred.
Should I override the OnException() method in the controller or is there an alternative and better way of handling this? If not, how would I be able to identify if a request is a Get or Post method?
I would like to handle all POST errors clientside if possible if that's the recommended method of handling errors.