openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

OData V4 Context does not support error handling.

Open TheGreenToaster opened this issue 7 years ago • 12 comments

OpenUI5 version:*

Steps to reproduce the problem:

  1. Call create method on list binding in direct mode.
  2. Use the context to retrieve the promise
  3. The create call fails.

What is the expected result? A catchable exception to be thrown or the create promise to be rejected. So that the calling method would be able to handle the calls failure.

What happens instead? Nothing.

TheGreenToaster avatar Jan 24 '19 17:01 TheGreenToaster

Hello @TheGreenToaster !

Thanks for your interest in OData V4. To better serve your needs, it might be helpful to get some background on what you are trying to achieve.

v4.Context#create is currently optimized for UI use cases, where the user presses an "Add" button, enters some data, and then presses "Save". Our assumption was that if the actual POST fails, it is usually because of invalid input. To this end, the error message is reported to the error model and should thus be shown on the UI. The user can correct his input and press "Save" again and the POST will be repeated. There is no point in telling some controller code that the 1st POST failed.

In case you have a use case w/o UI, your mileage may vary and maybe you miss s.th.

Best regards, Thomas

ThomasChadzelek avatar Jan 25 '19 09:01 ThomasChadzelek

Hey @ThomasChadzelek,

Thanks for the quick reply.

My primary use case is a little odd. I have a set of fields being returned from the OData where one row equals 1 field on the screen. When the user enters a value into a previously unpopulated field the it triggers a create because the record for that field did not previously exist. I will of course validate the input but I also wanted to pass any errors from the POST call through to the user as well as reset the value of the field.

My second use case is a bit more traditional. I have a tokenizer that I am adding tokens to through a "+" button and deleting using a "X" button on the tokens. This is the design we are trying to use. The user selects the valid values in a select dialog but we would still like to handle any unforeseen errors that might occur in the service.

I have the view registered to the message manager but it did not help.

Thanks again for your help

TheGreenToaster avatar Jan 25 '19 20:01 TheGreenToaster

Hi @TheGreenToaster ,

I am a colleague of Thomas.

Let me start with a short question: Which updateGroupId are you using? Please see chapter Batch Control in the documentation for reference!

In combination with v4.ODataModel.submitBatch you can use v4.Context.isTransient to find out whether the POST worked. In general you would use method hasPendingChanges to find out if there are unsaved changes. This method is available at different objects/with different scopes:

Note, that the promise returned by v4.ODataModel.submitBatch will fail only if the whole batch request failed.

Please have a look at chapter Message Model of the documentation for a starting point for using the message model! You will need to bind the message model in a control, e.g. a sap.m.MessagePopover. You may also register a change event to this binding to be informed about changes, e.g. when new messages are pushed into the message model or old messages are removed. Please see also the OData V4 SalesOrders sample application in the SAPUI5 demokit and in particular methods onInit, handleMessagesChange and onMessagePopoverPress of Main.controller.js!

Best regards Mathias.

uhlmannm avatar Feb 04 '19 15:02 uhlmannm

Hey @uhlmannm,

Thanks for your reply.

We are using the $direct updateGroupId to implement the "Local Flow" pattern on an object page. We have been trying to avoid batch requests as it makes our testing more difficult when we want to stub requests. We also have not seen any negative performance from keeping the requests separate. I read in some of the documentation that staging changes does not work in $direct mode.

I have been reading the documentation you suggested on the Message Model and MessagePopover. Best I can tell this would be very useful for validations but I dont see how it would work with failures in the service?

Thanks again, Nathan

TheGreenToaster avatar Feb 06 '19 16:02 TheGreenToaster

Hi Nathan (@TheGreenToaster) ,

We are using the $direct updateGroupId to implement the "Local Flow" pattern on an object page. We have been trying to avoid batch requests as it makes our testing more difficult when we want to stub requests. We also have not seen any negative performance from keeping the requests separate. I read in some of the documentation that staging changes does not work in $direct mode.

Generally, I would recommend to work with batch groups in the productive application. During development $direct can be very helpful. For example, when servers use ETags it needs to be ensured that each request carries the correct ETag. This is ensured with batch requests (cf. What's New in SAPUI5 1.60) but not with updateGroupId $direct.

I have been reading the documentation you suggested on the Message Model and MessagePopover. Best I can tell this would be very useful for validations but I dont see how it would work with failures in the service?

The model creates messages in the message model for failed requests. These messages can be displayed to show to the user that there was a technical error.

Best regards Mathias.

uhlmannm avatar Feb 06 '19 16:02 uhlmannm

Hi @uhlmannm,

Please see also the OData V4 SalesOrders sample application in the SAPUI5 demokit and in particular methods onInit, handleMessagesChange and onMessagePopoverPress of Main.controller.js!

As far as I can see, some coding seems to be missing. init call initMessagePopover, but I could't found implementation of initMessagePopover, as well as for message change and popover press handlers.

Would be great to have some sample code.

-Steffen

citoki avatar Jul 26 '19 06:07 citoki

Hi Steffen (@citoki ),

this functionality has been centralized to reuse it in several sample and internal test applications. There seems to be an issue with demokit showing https://github.com/SAP/openui5/blob/master/src/sap.ui.core/test/sap/ui/core/demokit/sample/common/Controller.js as well. Please check it directly in Github!

Best regards Mathias.

uhlmannm avatar Jul 26 '19 06:07 uhlmannm

@Steffen: the V4 SalesOrder sample unfortunately is not self-contained. It refers to a shared controller but does not list it in its download list.

See https://github.com/SAP/openui5/blob/master/src/sap.ui.core/test/sap/ui/core/demokit/sample/common/Controller.js for the missing code pieces.

codeworrior avatar Jul 26 '19 06:07 codeworrior

@uhlmann The files are not listed in the manifest.json, therefore they are neither shown nor downloaded in the SDK.

codeworrior avatar Jul 26 '19 06:07 codeworrior

Hi Steffen (@citoki ),

with SAPUI5 1.70 the missing files are available in the demokit. Please see https://sapui5.hana.ondemand.com/1.70.0/#/entity/sap.ui.model.odata.v4.ODataModel/sample/sap.ui.core.sample.odata.v4.SalesOrders/code.

Best regards Mathias.

uhlmannm avatar Sep 17 '19 06:09 uhlmannm

Hi Nathan (@TheGreenToaster ),

the issue has been open now for a while without any further discussions. Is there still something that needs to be clarified? Or could we close the issue?

Best regards Mathias.

uhlmannm avatar Sep 17 '19 06:09 uhlmannm

Since there is no response from the author for more than 4 weeks I'm closing the ticket.

Martotko avatar Dec 21 '20 13:12 Martotko