cancel
Showing results for 
Search instead for 
Did you mean: 

How to display the business exception in the image handling?

Jayakrishnan
Active Participant
0 Kudos
237

Hi All,

I am working on Custom SAPUI5 Development, in which i need to display the image from the OData Service. I used sap.m.Image control to display the Image . I used the below code to set the image to the control.

Code:

var sNewURI = "/sap/opu/odata/sap/ZSERVICE_SRV/ImageSet(Guid=guid'" + sGUID + "',value2='" + svalue + "')/$value";
oDisplayImage.setSrc(sNewURI);

The above code is working, i can see the image in the application. and i set the Not Found Message in the sap.m.Image

alt property.

But in my application scenario, i have to display the proper business exception when the image is not loaded from the service.

So i tried to read the service and handle the error message in the alt property in sap.m.Image.

My code to read the Service:

oView.getModel().read("/ImageSet(Guid=guid'" + sGUID + "',value2='" + svalue + "')/$value", {
				success: function (oResults, oResponse) {	
				},
				error: function (oError) {
					
				}
			});

In above code when some error happened in the back end, it successfully triggers the error handler, and i can see the proper business exception in the error details tag.

But for the Success also it is triggers the same error handler and i received the error message saying,

no handler for data.

Please help me sort out this issue.

Thank you,

Regards,

JK.

WouterLemaire
Active Contributor

not an answer to your question but why not returning a dummy image in case you do not have one?

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member187227
Participant
0 Kudos

Hi jayakrishnan.chnadramohan,

You can try ajax call, being able to handle the error using that. Check the below code.

Thanks,

jQuery.ajax({
				type: "GET",
				url: "/sap/opu/odata/sap/ZGEPMGS002_SRV/" + key + "/$value",
				contentType: false,
				processData: false,
				xhrFields: {
					responseType: "blob"
				},
				success: function (response, status, xhr) {
					 
				},
				error: function (oError) { 
					var sErrMessageXML = oData.response.body;
					sap.m.MessageBox.error(jQuery.parseXML(sErrMessageXML).querySelector("message").textContent);
				}
			});