I am creating a server with Flask and it has quite a few routes. Most routes require a specific state, such as “logged in” or “process started”. All of my functions and methods in packages will throw certain type of exceptions when the specific state is not matched. At the end my code ends up like this:
@app.route("/sayHello") def sayHello(): try: name = get_session_data("user", "name") # Some other stuff that throw meaningful exceptions return someTemplate except NotLoggedIn: return flask.redirect(flask.url_for("login")) except UserNotReadyToSayHello: return "You are not ready to say hello!", status.HTTP_400_BAD_REQUEST except UserHelloMessageNotDefined: return "You did not set up a greeting message!", status.HTTP_400_BAD_REQUEST except ConnectionToDatabaseFailed: return "Cannot access database", status.HTTP_500_INTERNAL_SERVER_ERROR except UnexpectedError: return "Something happened", status.HTTP_500_INTERNAL_SERVER_ERROR
Of course this is just an example I made up to demonstrate the problem, however it is more or less equivalent to the actual code.
This made programming the routes much easier than checking everything with
if statements everywhere, however I ended up with a lot of
except cases to the point where PyLint is telling me
Too many return statements (9/6)
How should I handle this situation? A lot of routes actually share a very similar sets of
✓ Extra quality
ExtraProxies brings the best proxy quality for you with our private and reliable proxies
✓ Extra anonymity
Top level of anonymity and 100% safe proxies – this is what you get with every proxy package
✓ Extra speed
1,ooo mb/s proxy servers speed – we are way better than others – just enjoy our proxies!
USA proxy location
We offer premium quality USA private proxies – the most essential proxies you can ever want from USA
Our proxies have TOP level of anonymity + Elite quality, so you are always safe and secure with your proxies
Use your proxies as much as you want – we have no limits for data transfer and bandwidth, unlimited usage!
Superb fast proxy servers with 1,000 mb/s speed – sit back and enjoy your lightning fast private proxies!
99,9% servers uptime
Alive and working proxies all the time – we are taking care of our servers so you can use them without any problems
No usage restrictions
You have freedom to use your proxies with every software, browser or website you want without restrictions
Perfect for SEO
We are 100% friendly with all SEO tasks as well as internet marketing – feel the power with our proxies
Buy more proxies and get better price – we offer various proxy packages with great deals and discounts
We are working 24/7 to bring the best proxy experience for you – we are glad to help and assist you!