on 02-26-2015 11:35 AM
Hi all,
I have an input field in the frontend which gets some records and displays them .Now if the respective record is not found due to some issue or if bapi is failed i want to raise the message in the frontend .
if i just raise the below exception code in my method in sap gateway is it going to take care of message handling or i have do anything in the font end too?
raise exception type /iwbep/cx_mgw_busi_exception
exporting
textid = /iwbep/cx_mgw_busi_exception=>business_error
message = message.
Thanks for support help me out..
I searched the prior articles and found the the above code i could not find if anything needs to be done in frontend apart from backend exception call.
thanks
when add the following exception call in get_stream method i am getting this message which i had set from backend in the console and error_log
exception call made in backedn
raise exception type /iwbep/cx_mgw_busi_exception
exporting
textid = /iwbep/cx_mgw_busi_exception=>business_error
message = 'message frm sap'.
console message
gateway error log
But its not getting displayed in the screen popup? what i found is
(err.response.body).error.message.value) is triggering syntax error.I tried to get the response
var obj = JSON.parse(err.response.body); but at this point the syntax error is triggered.
Error triggered is "ncaught SyntaxError: Unexpected token <" at this line
var obj = JSON.parse(err.response.body);
How do i over come it?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
what's in err.response.body? must be XML
try {
// Try to parse as a JSON string
oMessage = JSON.parse(oError);
} catch (err) {
try {
// Whoops - not JSON, check if this is XML
switch (typeof oError) {
case "string": // XML or simple text
if (oError.indexOf("<?xml") == 0) {
var oXML = jQuery.parseXML(oError);
var oXMLMsg = oXML.querySelector("message");
if (oXMLMsg) {
messageText = oXMLMsg.textContent;
}
} else {
// Nope just return the string
messageText = oError;
}
break;
case "object": // Exception
messageText = oError.toString();
break;
}
} catch (err) {
messageText = "An unknown error occurred";
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is code in controller
Please correct if i am wrong
I have placed the debugger in the get_Stream gateway method.The break point is hit when the above code in controller is executed.But still why does it goes to error function though the call to service was a success ?
But still why does my message text in err object doesnot change to what i passed from backend
Hello Deepan,
From the OData Read API Documentation ,
An OData model read operation (HTTP GET) has optional parameters including success and error callback functions. The error callback function can have the parameter oError which contains additional error information.
As an example, here is an OData Read with the optional parameter map:
this.getModel().read("/InvalidPath",{
context: {},
urlParamters: {},
async: true,
filters: [],
sorters: [],
success: function(){
},
error: function(oError){
console.log(oError);
}
});
The oError object's message, request, and response can be examined in the console. JSON.parse can be to parse the error's message body string as JSON for further handling, e.g. an error message in a sap.m.MessageBox.
Regards,
Scott
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi thanks,
I using the following code
var sRead = "/formset(orderno='" + sordno + "')"+"/$value";
oModel.read( sRead, null, null, true, function(oData, oResponse){
$('#detailPage--frame').attr('src',oResponse.requestUri);
debugger;
},function(err) {
//Error Callback:
alert("Error occurred " + err.message)});
}
here err.message will have the error text passed from backedn right?
This is how i passed the message from backend
can you show how to add the message my code snippet?
when i use error: function() i am getting syntax error "Syntax error on token ":"" .sorry for too basic question i am in process of learning.
From back-end to front-end development, we certainly have a lot of opportunities for learning!
Try this (no promises),
this.getModel().read("/InvalidPath", {
context: {},
urlParameters: {},
async: true,
filters: [],
sorters: [],
success: function(oData, oResponse){
$('#detailPage--frame').attr('src',oResponse.requestUri);
debugger;
},
error: function(err) {
//Error Callback
jQuery.sap.require("sap.m.MessageBox");
sap.m.MessageBox.show((JSON.parse(err.response.body).error.message.value));
}
});
Regards,
Scott
Deepan,
I concur with Scott answer. Even though you may be able to pass those params to the read function without having a property: value , I'd suggest to do it like Scott's example as it will be more readable.
If you continue getting a syntax error on the front-end, open the browser developer tools (F12) and set a breakpoint in the error callback and use the console window to see the error object you are getting in order to determine its properties.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.