cancel
Showing results for 
Search instead for 
Did you mean: 

get message value of responseBody

0 Kudos

Hello,

I'm trying to show error message from backend using "JSON.parse(actionResult.error.responseBody).message.value". It is working correctly on web version, but not working on mobile. Could you please help me what I am missing here? I'd like to show only message.

    var actionResult = clientAPI.getActionResult('update');

    if (actionResult && actionResult.error) {
        if (actionResult.error.responseCode > 0) { 
            return 'Update Fail [' + actionResult.error.responseCode +'] ' + JSON.parse(actionResult.error.responseBody).message.value;
        } else {
            return actionResult.error.message;
        }
    }  
    return 'Entity failed to update.';

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Based on your log file value

{
    "error": {
        "responseCode": 400,
        "responseBody": "{
                \"code\": \"IWO_BAPI/124\",
                    \"innererror\":
                        {\n        \"Error_Resolution\":\n        {\n            \"SAP_Note\": \"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)\",\n            \"SAP_Transaction\": \"\"\n        },\n        \"application\":\n        {\n            \"component_id\": \"\",\n            \"service_id\": \"Z_SAMPLE_APP_SRV\",\n            \"service_namespace\": \"/SAP/\",\n            \"service_version\": \"0001\"\n        },\n        \"errordetails\":\n        [\n            {\n                \"code\": \"IWO_BAPI/124\",\n                \"longtext_url\": \"/sap/opu/odata/iwbep/message_text;o=ECC110/\",\n                \"message\": \"Order 2100123 is locked and cannot be changed\",\n                \"propertyref\": \"\",\n                \"severity\": \"error\",\n                \"target\": \"\",\n                \"transition\": false\n            }\n        ],\n        \"timestamp\": \"\",\n        \"transactionid\": \"79F79D7FEA2E0040E0061200C94DAC55\"\n    },\n    \"message\": \"Order 2100123 is locked and cannot be changed\"\n}",
        "line": 2,
        "column": 1911925,
        "sourceURL": "file:///app/vendor.js"
    },
    "status": -1,
    "enabled": true
}

there is no value property. I believe you should just reference the message property directly.

return 'Update Fail [' + actionResult.error.responseCode +'] ' + JSON.parse(actionResult.error.responseBody).message;
0 Kudos

You are absolutely right, Bill. The web version is returning with "value", but not on device. I was able to get the message just referring to message directly.

This is what I am getting from web version:

'{"code":"IWO_BAPI/124","message":{"lang":"en","value":"Order 2100123 is locked and cannot be changed"},"innererror":{"application":{"component_id":"","service_namespace":"/SAP/","service_id":"Z_SAMPLE_APP_SRV","service_version":"0001"},"transactionid":"79F79D7FEA2E00A0E006148F1C672AC6","timestamp":"","Error_Resolution":{"SAP_Transaction":"","SAP_Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"},"errordetails":[{"code":"IWO_BAPI/124","message":"Order 2100123 is locked and cannot be changed","longtext_url":"/sap/opu/odata/iwbep/message_text;o=ECC110/","propertyref":"","severity":"error","transition":false,"target":""}]}}'

I still don't have a knowledge to understand clearly why this return could be different between on the device and web, but I learned at least it could be different! 🙂

Thanks for all your help, Bill.

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

The response body is based on the odata library / sdk being used and it looks like the web version returns the data in a slightly different format. Looks like you will just need to wrap it with some platform specific logic to retrieve the values or reference the message from JSON.parse(actionResult.error.responseBody).innererror.errordetails.message which appears to be the same between the platforms.

Answers (1)

Answers (1)

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

When you say it is not working on Mobile is it giving an error or just not displaying data?

What version of the MDK client are you using and on what platform (iOS or Android)?

It is also important to note that this is dependent on what the backend is actually returning. It might be for the particular error the backend is not returning the message.

0 Kudos

Hi Bill,

On web version, it is showing 'Order xx is locked and cannot be changed.'. But, it shows 'undefined' on iPad.

In BAS, I chose MDK 6.0+.

(sorry... image wasn't uploaded properly. Attached it again).

Thanks.

0 Kudos

Hi Bill,

I updated the previous posting with attachment of the actionResult. Could you please take a look?

Thanks!

bill_froelich
Product and Topic Expert
Product and Topic Expert
0 Kudos

Have you checked the value of the action result on the mobile?

    var actionResult = clientAPI.getActionResult('update');

    if (actionResult && actionResult.error) {
        let logger = clientAPI.getLogger();
        logger.log(JSON.stringify(actionResult));
        if (actionResult.error.responseCode > 0) { 
            return 'Update Fail [' + actionResult.error.responseCode +'] ' + JSON.parse(actionResult.error.responseBody).message.value;
        } else {
            return actionResult.error.message;
        }
    }  
    return 'Entity failed to update.';

Note the logger lines I added. After running this on the mobile, check the client log from your emulator or device and see what actionResult contains to verify

0 Kudos

Hi Bill,

I have been developing an app using BAS since I am having an error when I execute "create-client" on my local machine. So I tried to upload client log file to mobile service to see the above issue as you recommended. But, unfortunately, I just got an answer via another thread there is a bug to download log files from corporate account in us10 server. I tried it in trial account, but only 100 lines are allowed. Is there a way I can check more to fix this issue?

When I put alert(JSON.parse(actionResult.error.responseBody).message.value), I see correct error message, 'order xxx is locked and cannot be changed'. But, when I concatenate it, it shows 'Update Fail [400] undefined'.


Any help would be appreciated.

0 Kudos

Hi Bill,

I added the code you suggested and checked the value from the client log file:

The coded added:

let logger = clientAPI.getLogger();
logger.log(JSON.stringify(actionResult));


The value in log file:

{"error":{"responseCode":400,"responseBody":"{\n    \"code\": \"IWO_BAPI/124\",\n    \"innererror\":\n    {\n        \"Error_Resolution\":\n        {\n            \"SAP_Note\": \"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)\",\n            \"SAP_Transaction\": \"\"\n        },\n        \"application\":\n        {\n            \"component_id\": \"\",\n            \"service_id\": \"Z_SAMPLE_APP_SRV\",\n            \"service_namespace\": \"/SAP/\",\n            \"service_version\": \"0001\"\n        },\n        \"errordetails\":\n        [\n            {\n                \"code\": \"IWO_BAPI/124\",\n                \"longtext_url\": \"/sap/opu/odata/iwbep/message_text;o=ECC110/\",\n                \"message\": \"Order 2100123 is locked and cannot be changed\",\n                \"propertyref\": \"\",\n                \"severity\": \"error\",\n                \"target\": \"\",\n                \"transition\": false\n            }\n        ],\n        \"timestamp\": \"\",\n        \"transactionid\": \"79F79D7FEA2E0040E0061200C94DAC55\"\n    },\n    \"message\": \"Order 2100123 is locked and cannot be changed\"\n}","line":2,"column":1911925,"sourceURL":"file:///app/vendor.js"},"status":-1,"enabled":true}

The message seems ok to me. But, when I use JSON.parse(actionResult.error.responseBody).message.value, I get empty value. Can you take a look what I am missing here?

Thanks.