PDA

View Full Version : Customer Exception Using ASP.Net



azinyama
28 Aug 2012, 4:27 AM
Hi all!!!

I have store that I'm loading as follows:



Ext.define('Test.store.Tariff',
{
extend : 'Ext.data.Store',
id : 'Tariffs',
autoLoad : false,
autoSave : false,
autoSync : true,
remoteSort : true,
pageSize : 100,
paramOrder : 'start|limit|page|search',
model : 'Test.model.Tariff',
proxy : {
type : 'direct',
reader : {
type : 'json',
successProperty : 'success',
totalProperty : 'total',
root : 'data',
idProperty : 'Tariff_RowID'
},
writer : {
type : 'json',
encode : false,
writeAllFields : true
},
api : {
create : _tariffHandler.Create_Tariff,
read : _tariffHandler.Load_Tariff,
update : _tariffHandler.Update_Tariff,
destroy : _tariffHandler.Delete_Tariff
},
listeners : {
exception : function(proxy, response, operation)
{
Ext.MessageBox.show(
{
title : 'Remote Exception',
msg : operation.getError(),
icon : Ext.MessageBox.ERROR,
buttons : Ext.Msg.OK
});
}
},
updateCallback: function (request, success)
{
if (!request.operation.success && request.operation.hasException())
{
console.log(request.operation);
Ext.Msg.show(
{
title : 'Tariff Update Error',
msg : request.operation.getError(),
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.ERROR
});
}
}
}
});


I'm using ASP.Net in the background to get the data. This works fine. My question is if an exception occurs on the ASP.Net side how to I capture that custom error message. The exception listener I have attached to the store doesn't seem to capturing the exception message being sent. ASP.Net code below:




<DirectMethod()> _
<ParseAsJson()> _
Public Function Update_Tariff(ByVal o As JObject) As Tariff
Dim t As Tariff = Nothing

Try
'ASSUME NEXT TWO LINES FAIL AND MOVE TO CATCH AND THROUGH EXCEPTION
t = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Tariff)(o.ToString())
t.Tariff_Update()
Catch ex As DirectException
Throw New DirectException("CUSTOMR EXCEPTION MESSAGE BEING SEND HERE") '<--- CUSTOMR EXCEPTION MESSAGE BEING SENT HERE BUT
End Try

Return t
End Function


So at the end of the day I would like the message "CUSTOMR EXCEPTION MESSAGE BEING SEND HERE" show in a messagebox to the user... But at the moment it only returns the message '
Error occurred while calling Direct method: Exception has been thrown by the target of an invocation.';

Thanx in advance

scottmartin
28 Aug 2012, 10:15 AM
Your return json should return the message:


{
success: false,
message: 'There was an error', ...
}

In your callback response, you can capture and display this message


var jResponse = Ext.decode(xhr.responseText);
if (jResponse.success === false) {
alert(jResponse.message);
}

Scott.

azinyama
30 Aug 2012, 12:38 AM
Thanx for the response. Will give it a try...

azinyama
4 Sep 2012, 2:36 PM
Thanks worked. Changed it to this:





<DirectMethod()> _
<ParseAsJson()> _
Public Function Update_Tariff(ByVal o As JObject) As JObject
Dim t As Tariff = Nothing

Try
t = Newtonsoft.Json.JsonConvert.DeserializeObject(Of Tariff)(o.ToString())
t.Tariff_Update()
Catch ex As DirectException
Return New JObject(New JProperty("success", False), New JProperty("message", ex.Message))
End Try

Return JObject.Parse(JsonConvert.SerializeObject(t))
End Function