Skip to Content
Technical Articles
Author's profile photo Daniele Incampo

Show backend errors in SAPUI5 app using bapiret2_t

Hi everyone,


I’m Daniele Incampo SAPUI5 and HANA’s developer.

I’m writing my first blog post so I hope you will be understanding.

Here is a simple SAPUI5 example of how to show backend errors.

I’m writing this because I found many obstacles during my app development. So I would like to be helpful  for those like me who are novice with SAPUI5.




Into YOURENTITY_GET_ENTITY (my use case) or any other method of ZCL_YOURPROJECT_DPC_EXT (I think it shoud works):



 DATA: lo_meco TYPE REF TO /iwbep/if_message_container,
 lx_busi_exc TYPE REF TO /iwbep/cx_mgw_busi_exception,
 lt_log TYPE bapiret2_t.


(In my case, errors were reported with ‘E’ or ‘A’)

IF lt_log IS NOT INITIAL. "Se vengono restituiti dei messaggi
 LOOP AT lt_log INTO DATA(ls_log) WHERE type EQ 'E' OR type EQ 'A'.
 IF sy-subrc EQ 0. "Se ci sono messaggi di errore
 lo_meco = mo_context->get_message_container( ).
 it_bapi_messages = lt_log
 CREATE OBJECT lx_busi_exc
 message_container = lo_meco.
 RAISE EXCEPTION lx_busi_exc.

The result will be something like this :



After creating the project, the structure is like this. We will focus on writing code into the Utilities.js (You can easily find how to create this here: )

After you create, you need to import into your controller like this :

], function (Controller, JSONModel, MessageBox, Utilities) {
"use strict";

So now you will be able to use Utilities.js functions into standard Main.Controller.js simply referring with Utilities.function();

After read your entity set, you have to specify success and error functions. You should write something like this:

We will focus on error function, what you will write into success function is irrelevant for this blog post. So, we will retrieve errors from backend in this way:

var a = JSON.parse(response.responseText);
var errDetails = a.error.innererror.errordetails;

That’s why you can see debugging the code:




That’s how it works for me.
I made something like the sample of MessageView ( ) with some customization like a preview message as title, signal error by severity, exc.

], function (Controller, JSONModel, Link, Icon, MessageItem, MessageView, Button, Bar, Text, Dialog) {
"use strict";
return {
initMessage: function (errDetails) {
// var oLink = new Link({
// text: "Show more information",
// href: "",
// target: "_blank"
// });
var a = this.getText("year");
var oMessageTemplate = new MessageItem({
type: '{type}',
title: '{title}',
description: '{description}',
subtitle: '{subtitle}',
counter: '{counter}',
markupDescription: '{markupDescription}'
// link: oLink
var aMockMessages = [];
for (var i = 0; i < errDetails.length; i++) {
var name = errDetails[i].severity;
var nameCapitalized =
name.charAt(0).toUpperCase() + name.slice(1);
var semiDescription =
errDetails[i].message.slice(0, 10);
semiDescription =
var oMockMessage = {
type: nameCapitalized,
title: semiDescription,
description: errDetails[i].message
var oModel = new JSONModel();
var that = this;
var oBackButton = new Button({
icon: sap.ui.core.IconPool.getIconURI("navback"),
visible: false,
press: function () {
this.oMessageView = new MessageView({
showDetailsPageHeader: false,
itemSelect: function () {
items: {
path: "/",
template: oMessageTemplate
this.oDialog = new Dialog({
resizable: true,
content: this.oMessageView,
state: 'Error',
beginButton: new Button({
press: function () {
text: "Close"
customHeader: new Bar({
contentMiddle: [
new Text({
text: "Error"
contentLeft: [oBackButton]
contentHeight: "300px",
contentWidth: "500px",
verticalScrolling: false
manageErrors: function (errDetails) {

And that’s the final result:


We achieved the goal to show errors coming from back-end into our app using Utilities.js and bapiret2_t as type table.

Please comment if you have any queries. Also request you to let me know if any changes required.




Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Aleksandr karpov
      Aleksandr karpov

      Hi Daniele.

      Good blog. Thanks.

      And why you don't use MessageManager, in my opinion it is mode suitable?

      Author's profile photo Daniele Incampo
      Daniele Incampo
      Blog Post Author

      Hi Aleksandr,


      I agree with you.

      However in my use case, the customer wanted something to pop up and I chose MessageView.


      Thanks for your comment.

      Author's profile photo Aleksandr karpov
      Aleksandr karpov

      Thanks Daniele.

      You made the right decision