Getting KeyError of missing `code` argument - keyerror

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.

Related

HealthCheckUI (AspNetCore.Diagnostics.HealthChecks) Unexpected Character 'H' error

I'm having an issue with the AspNetCore HealthCheckUI.
I followed this example:
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks#healthcheckui
My UI is up and running and my services are up and running with a healthcheck that just returns a string "Healthy". And I think that's the root cause of the issue.
It looks like the UI is showing a "false" error because it's expecting JSON and seeing a string. And so it's throwing an "Unexpected character 'H'" error while parsing the response.
Is there a way to stop the healthcheckui from expecting json?
Is there a way have this AspNetCore HealthChecksUI package work with a Healthcheck that doesn't return JSON?
Found the closest thing I could find to an answer, which is basically change all my healthchecks to json :(
https://github.com/Xabaril/AspNetCore.Diagnostics.HealthChecks/issues/440

When I call the balanceOf function for a contract and specify a block number in call(), I receive a forbidden URL error

When I use contract.functions.balanceOf(wallet_address).call(block_identifier=block_num) I get a forbidden URL error, but if I run the same call without using the block_identifier argument, it works as expected. What is the reason that this is happening?

Flask Error: If something fails in the flask backend, how does the error propagate to the front end?

Consider a simple application where a user fills a form to divide two numbers, in the routes the form data is proceeded [made into float] and then passed as parameters to a python script's function that has the division logic.
The logic fails due to division by 0 is handled as a custom message in the terminal. How does one send this custom message back to the front end UI along with a 500 error message? Trying to make a restful flask app here.
So far I can abort and show a custom message but not the one that propagated from the backend. Also looked into custom error handling but I want to writer of the external python script to be able to write the custom message.
You can Flask errorhandler(errorcode) to manage your errors and display those on the frontend.
#app.errorhandler(500)
def code_500(error):
return render_template("errors/500.html", error=error), 500
You can put whatever else you want in the html template.
You can also call the code_500(error) func directly.
Same principle applies for any other HTTP error code if you want to customize the page and the message (401, 403, 404, etc...).
If you're inside a blueprint, you can use app_errorhandler instead.
You could use the abort() function. From the docs:
When using Flask for web APIs, you can use the same techniques as above to return JSON responses to API errors. abort() is called with a description parameter. The errorhandler() will use that as the JSON error message, and set the status code to 404.
You could implement it like this
#app.route("/div")
def divide():
x, y = request.form['x'], request.form['y']
try:
result = x / y
except ZeroDivisionError:
abort(400, description="Your message here")
else:
# Proper response
From there, the important step is properly catching that message on your frontend.

(Akka-HTTP) How to specify a custom reason?

I am trying to respond with a custom reason code. For example:
404 Didn't find it anywhere!
or
400 Bad Request: missing parameter 'a'
How is this done with Akka HTTP?
Not sure if you mean a custom status code or a custom reason.
To return a 404 status code you can simply return:
HttpResponse(404)
To return a customized reason you can return:
HttpResponse().withStatus(StatusCodes.custom(404, "Didn't find it anywhere!", ""))

Nest1.0: ConnectionStatus error handling

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.