Fetching error message in Mule 4 not working - error-handling

I run the code in debug mode and realized that external service is returning me error message below error message is coming in the path
error.exception.cause.errorMessage.typedValue.value
Its value is as below.
typedValue.value = {"status"":"Bad Request", "message":"Invalid data"}
I want to get the message "Invalid data" in var.
My code is as follows
output application/java
var adminEmail = vars.adminEmail
var salesRepEmail = if (!isEmpty(vars.InitialRequest.Application.PreliminaryQuestions.SalesRepresentative.EmailAddress))
[vars.InitialRequest.Application.PreliminaryQuestions.SalesRepresentative.EmailAddress]
else
p('emailNotifications.nonStarterNotification.defaultEmail') splitBy(",")
var declineReason = error.exception.cause.errorMessage.typedValue.value
I have tried
var declineReason = if(error == null) vars.errorDescription else (error.exception.cause.errorMessage.typedValue.value default "Bad request") as String
Also tried
var declineReason = if(error == null) vars.errorDescription else flatten(error.exception.cause.errorMessage.typedValue.value.message)
error.exception.cause.errorMessage.typedValue.value returns null.

Related

Want to know about authentication error /creational invalid in power BI i call rest API

When i call rest API by using following line of code that time, I'm pass my Power BI desktop username and pass but its showing error
() =>
let body = [username = "Username", password = "----"],
Data = Json.Document(Web.Contents("URL", [Headers = [# "Content-Type" = "application/json"], Content = Json.FromValue(body)])),
result = Record.Field(Data[result] {
0
}, "token")
in
result
refer this code I'm trying but I found error

HTTP request won't get data from API. Gamemaker Studio 1.4.9

I'm trying to figure out how to get information from a dictionary API in Gamemaker Studio 1.4.9
I'm lost since I can't figure out how to get around the API's server block. All my return shows is a blank result.
Step Event:
if(keyboard_check_pressed(vk_space)){
http_get("https://api.dictionaryapi.dev/api/v2/entries/en/test");
}
HTTP Event:
var requestResult = ds_map_find_value(async_load, "result");
var resultMap = json_decode(requestResult);
if(resultMap == -1)
{
show_message("Invalid result");
exit;
}
if(ds_map_exists(resultMap,"word")){
var name= ds_map_find_value(resultMap, "word");
show_message("The word name is "+name);
}
Maybe my formatting is wrong? It's supposed to say the word test in the show_message function, but again, all I get returned is a blank result.
Any help would be appreciated, thanks!
You can see through the debugger that the data is coming from the server. But your code does not correctly try to retrieve the Word.
https://imgur.com/a/icQSnnx
This code gets this word
show_debug_message("http received")
var requestResult = ds_map_find_value(async_load, "result");
var resultMap = json_decode(requestResult);
if(resultMap == -1)
{
show_message("Invalid result");
exit;
}
if(ds_map_exists(resultMap,"default")){
var defaultList = ds_map_find_value(resultMap, "default")
var Map = ds_list_find_value(defaultList, 0)
var name= ds_map_find_value(Map, "word");
show_message("The word name is "+name);
}

How does ibm - mobile first get mobile number from security context?

I am following "isRegistered" api from this sample code. I did not understand how we get phone number from security context.
The API that I want to use is:
#Path("/isRegistered")
#GET
#Produces("application/json")
#OAuthSecurity(enabled = true)
#ApiOperation(value = "Check if a phone number is registered",
notes = "Check if a phone number is registered",
httpMethod = "GET",
response = Boolean.class
)
#ApiResponses(value = {
#ApiResponse(code = 200, message = "OK",
response = String.class),
#ApiResponse(code = 401, message = "Not Authorized",
response = String.class),
#ApiResponse(code = 500, message = "Cannot check if phone number is registered",
response = String.class)
})
public Boolean isRegistered() {
//Getting client data from the security context
ClientData clientData = securityContext.getClientRegistrationData();
if (clientData == null) {
throw new InternalServerErrorException("This check allowed only from a mobile device.");
}
String number = clientData.getProtectedAttributes().get(SMSOTPSecurityCheck.PHONE_NUMBER);
return number != null && !number.trim().equals("");
}
How does the security context have the client phone number?
There is a client project as well in this sample. Please refer to the complete sample.
Within the client side logic here, the user is asked to provide the phone number , which is sent to the server in an adapter call:
MainViewController.codeDialog("Phone Number", message: "Please provide your phone number",isCode: true) { (phone, ok) -> Void in
if ok {
let resourseRequest = WLResourceRequest(URL: NSURL(string:"/adapters/smsOtp/phone/register/\(phone)")!, method:"POST")
.....
Now in the adapter code path #Path("/register/{phoneNumber}") notice the following code:
clientData.getProtectedAttributes().put(SMSOTPSecurityCheck.PHONE_NUMBER, phoneNumber);
securityContext.storeClientRegistrationData(clientData);
This is how the phone number made it to the security context.
Run the sample and use a tool such as Wireshark to analyze the data flow between client and server.

create user with umbraco webservice

I'm trying the following code:
var myCarrier = new memberCarrier()
{
DisplayedName = "abemad123",
Email = "abemad123#gmail.com",
LoginName = "abemad123",
MembertypeId = 1062,
Id = 3,
Password = "abe"
};
var client = new UmbracoWebService.memberServiceSoapClient();
var tmp = client.create(myCarrier, 1062, "abemad123", "abemad123");
But I get this error:
Server was unable to process request. ---> No User exists with ID -1
What am I doing wrong?
Bug in Umbraco.
If user/pass to the webservice doesn't match it throws an exception "No User exists with ID -1"
Error should be: "Wrong password"

Why messages are not added in Json response like error messages

If I use 'web-send-json-response="true"' while calling any service, it returns json response using sendJsonResponse(Object responseObj) method of WebFacadeImpl.groovy.
Where It adds 'errors' to json response if 'eci.getMessage().hasError()' true. But, Is there any reason why messages are not added in Json Response?
As I am willing to have messages in json response, I added few lines in sendJsonResponse() method.
The code block where I added few lines to add messages to json response:
} else if (responseObj != null) {
responseObj.put("messages", eci.message.messages)
JsonBuilder jb = new JsonBuilder()
jb.call(responseObj)
jsonStr = jb.toString()
response.setStatus(HttpServletResponse.SC_OK)
} else {
jsonStr = ""
if (eci.message.messages) {
responseObj.put("messages", eci.message.messages)
JsonBuilder jb = new JsonBuilder()
jb.call(responseObj)
jsonStr = jb.toString()
}
response.setStatus(HttpServletResponse.SC_OK)
}
It works fine and I am getting messages in json response.