on 10-26-2021 3:55 PM
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.
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;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
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.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.