on 05-16-2017 3:24 PM
Hey,
i am currently writing my first program using sapui5.
i have already implemented all CRUD functions.
my question:
in my CREATE function i am calling another function to check the input.
now i want to implement EXCEPTIONS into my programm.
how do i get the EXCEPTIONS thrown at the backend to my frontend page.
so as an example:
i want to create an entry, but this entry already exists in my database.
so my CREATE_ENTITY function would throw an exception.
how do i show this exception in the frontend.
currently this is my call to the create function:
oModel.create('/RoomsSet', oNewRoom, { success : function(oData, oResponse) {
sap.m.MessageToast.show("Room succesfully created! Reload Page to see changes");
sap.ui.getCore().byId("Popup").destroy();
},
error : function(oError) {
sap.m.MessageToast .show("There was an Error creating the room");
}
});
Put a breakpoint or use console.log(oError). In most case error will be under node message.
var oXML = jQuery.parseXML(oError.response.body);
var oXMLMsg = oXML.querySelector("message");
MessageBox.error(oXMLMsg.textContent);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I assume you are using the ODataModel (https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.odata.ODataModel.html#create). This is a JavaScript-Promise, so you need to handle it a bit different:
oModel.create('/RoomsSet', oNewRoom)
.then(function(oData, oResponse) {
sap.m.MessageToast.show("Room succesfully created! Reload Page to see changes");
sap.ui.getCore().byId("Popup").destroy();
})
.catch(function(oError) {
sap.m.MessageToast.show("There was an Error creating the room");
});
If you want to read more about Promises: https://www.promisejs.org/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If your OData service is returning any exception/error messages then those would be available within the oError parameter of the error callback function. You can check by setting a breakpoint in the error callback function in Chrome's developer console within the Source tab and check what values are retrieved in the oError parameter.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just used this code.
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception<br> EXPORTING<br> textid = /iwbep/cx_mgw_busi_exception=>business_error_unlimited<br> message_unlimited = 'Your message text'.
So if i make a wrong call to the Backend ( for example using a room_id that already exists). it says "There was an Error creating the room" and in the chrome debugger is see my error message: 'Your message text'.
Is there a way to show 'Your message text' inside my MessageToast ?
Edit: i found a work around:
i was looking through the error message in the console and found this workaround.
messageText = oError.responseText.split('message')[3];
sap.m.MessageToast.show(messageText);
Thank you for your input.
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.