Nest1.0: ConnectionStatus error handling - nest

I have a question regarding to Nest1.0pr and the connection error handling. In the previous versions of Nest I was using IResponse.ConnectionStatus.Error. It seems to me that the property Error does not exist in the new version anymore. However in the documentation I found the following:
ConnectionStatus is the response as it was returned by
Elasticsearch.net. It's section on handling responses applies here as
well.
And in the very section the property Error is mentioned.
Error When a call succeeds but does not return a http status code of
200 this property will have details on the error. Read more about
error handling here
So is the recommended way to check whether the property Success is false?
TIA

This changed when NEST was refactored to use Elasticsearch.Net. Now when a request fails, you can try checking the IResponse.ConnectionStatus.OriginalException property, which will contain the actual Elasticsearch error.

Related

Getting KeyError of missing `code` argument

I use authlib with MSAD and I am getting KeyError on line:
https://github.com/lepture/authlib/blob/master/authlib/integrations/flask_client/integration.py#L43
My question is if there has to be always code argument within request or IMHO this is bug and it should be checked by get() method same as state.
I use it with flask and after proper registration of MSAD client I try method authorize_access_token() and from here I get to the poit of code I mentioned above and get error.
Thanks for any advice.
Vit
Are you using debug mode of Flask? In production, this code will raise 400 Bad request error.

How to return both data field and errors field with Graphql-kotlin query

I am working on one server that resolve GraphQL queries. I used the graphql-kotlin library: https://github.com/ExpediaDotCom/graphql-kotlin.
I defined three resolve functions(could be viewed as three fields): getxxx(arguments...), getTarget(arguments...) and getSource(arguments...).
The problem is if one of my queried field failed, I will only get the 'errors' field. All other successful executed results(data) are dropped.
If I try to catch the exception for the failed field, then I will not get the 'error' field at last.
This is the image that had exception and dropped all fetched data:
The objective is returning both the successful fetched data in 'data' field and error message for failed field in 'errors' field.
I have checked this: How to return both error and data in a graphql resolver?
If I set a field that throw one error or exception intentionally, I will only get 'errors' field at last(Like the picture above).
In addition, many websites like this:https://itnext.io/the-definitive-guide-to-handling-graphql-errors-e0c58b52b5e1 suggest we should return partial result and error message, but in my case if I meet exception, only error message would be returned.
In our example application we have two top level queries
{
onlyCake(msg: "cake")
generateNumber
}
If I run this code this will return a random number and onlyCake returns the string <3. However if I modify the input of onlyCake to something that is not the string cake I will get an error. This is expected because the field onlyCake has a directive to implement this behavior.
https://github.com/ExpediaDotCom/graphql-kotlin/blob/2961b64d6e4cceb4034aec198d667e5f965decd2/example/src/main/kotlin/com/expedia/graphql/sample/directives/CakeOnlyDirectiveWiring.kt#L18-L19
The question is though, if I want to return the data still for generateNumber can I do that and have both errors and data in the response?
The answer is it's possible but not with the current schema. The issue is that our schema for onlyCake and generateNumber are both non-nullable fields. So as a client if I see that there is a data field I should expect to see both there otherwise I would have a parsing issue in my code. This is why we can't have this behaviour with the schema as is. If you want to implement this behaviour, the schema developer needs to decide where they can return null for some response and modify the errors field appropriately with a DataFetcherExceptionHandler
Or the other option is that we support the behaviour in graphql-java to return a DataFetcherResult<T> instead of just T from the kotlin functions. See the section Returning data and errors here: https://www.graphql-java.com/documentation/v13/execution/
I have created an issue to continue this discussion with other team members: https://github.com/ExpediaDotCom/graphql-kotlin/issues/244

How to get Error Message from previous connector Logic App

Is it possible to get and insert the previous connector's error message in a connector that gets triggered on failed after, to log the error message?
I did a seach and tested something like: #{body('XML_Validation')['message']}.
If so, is it also possible to get the Error code for the failed connector?
-----UPDATE-----
Ok so the previous test of #{body('XML_Validation')['message']} works on some connectors but not XML-Validation.
Is it still possible to extract the error message / exception somehow?
this is what i watch to get as a message to implement in another logic app:
Every action following the trigger-event can run under specific conditions. Defined like this in the code view:
"runAfter": {
"PreviousAction": [
"Succeeded"
]
}
You could set the "runAfter" to run on "Failed" and capture the message this way.
Have a look at: https://learn.microsoft.com/en-us/azure/logic-apps/logic-apps-exception-handling
Building on Steven's comment from the accepted answer, in my case I used the following:
#actions('Add_registrant_to_GoToWebinar')['outputs']['statusCode']
It allows to get the statusCode from the raw output of the connector, because this connector does not expose it.

How to get SimplePie to fail gracefully on invalid feed?

I'm trying to get SimplePie to fail gracefully if one of the feeds I hand it turns out to be unavailable or invalid (due to server issues on the feed provider's end)
The code I've got is this:
$this->feed= new SimplePie();
// Set which feed to process.
$this->feed->set_feed_url('http://my_feed_goes_here'); // Bogus
$this->feed->handle_content_type();
// Run SimplePie.
$this->feed->init();
The problem is, if the feed_url turns out to be invalid, I get the following error as soon as it hits $this->feed->init();
Fatal error: Call to undefined method DOMElement::getLineNo()
I've looked through the documentation, and I can't see anything about validating. I did see this page about error checking (http://simplepie.org/wiki/reference/simplepie/error) but that only really works if the URL is completely invalid and fails to load. In a case where the URL comes back with a 404, or something else that is not a valid feed, $feed->error is blank.
Isn't there some mechanism built into SimplePie to allow me to see whether I got a valid feed back, so I can fail gracefully if I didn't?
In SimplePie 1.3.1, ->init() will return false if it can't read or parse the URL, so you might do this:
if (! $feed->init()) {
// log your error, "return false" or handle the failure some other way
}
Based on my reading of simplepie\library\SimplePie.php, it doesn't generate any exceptions and that's why Try/Catch won't work.
This may not be built into SimplePie, but in your calling PHP you could use a try/catch block:
try {
$this->feed->init();
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
Although depending on the error, this might not work either.

How to Pass Error Code with Message in RestEasy

I am using the following code to send Error message.
This is my own error code and custom message. I am sending the message in response.
throw new WebApplicationException(
Response.status(1002)
.header(ae.getMessage(), ae)
.type(MediaType.TEXT_PLAIN)
.build());
The problem is, the front end guys are able to see the status code but not the message. Is there any other way to solve this issue?
You should use entity method to set message:
Response.status(1002)
.entity(ae.getMessage())
.type(MediaType.TEXT_PLAIN)
.build());