Comments (11)
Btw. the server returns "400 Bad Request" if the user name or password is wrong in the "api/auth/token/" call.
I think the best solution is that client._api_call()
should raise an error upon status_code != 200
, then client.auth_token()
should catch that and turn it into an error that says something about incorrect credentials.
from django-robo-cjk.
Come to think of it, what happens if you get a 401 on a 401? Is there a chance of a runaway recursion with the way this code is currently written? _api_call
is calling itself after all.
from django-robo-cjk.
-
About the error policy, actually it is possible to check the response status code, but raising an
Exception
would be surely more safe than possible silent errors, we could add asilent_errors=True
option to the constructor just to offer backward compatibility to the current implementation. -
This is technically impossible, because the API called for obtaining the auth token doesn't require authorization, so the 401 error (unauthorized) cannot be raised. If we want to discuss about the recursion, neither me I like it, but for now I think it is ok.
from django-robo-cjk.
Is there a case where the status_code
is anything else but a 200 and things actually keep on working?
What I observe now is that a wrong username results in AttributeError: 'NoneType' object has no attribute 'get'
a bit later, which is 100% unhelpful :)
from django-robo-cjk.
Also: backwards compatible from whom? We are the only users, no?
from django-robo-cjk.
I don't know if the response code is always checked or not in the client implementation.
The wrong username error seems strange, it should be surely improved. To reproduce it, is it enough to initialise the client with an invalid username? If not, could you tell me how to reproduce it, please?
Backward compatibility for our current implementation.
from django-robo-cjk.
I don't know if the response code is always checked or not in the client implementation.
Anything not 200 is an error, and therefore means you're not getting the response you hoped for. You cannot simply proceed and expect anything to work.
The wrong username error seems strange, it should be surely improved. To reproduce it, is it enough to initialise the client with an invalid username?
Yes, that's all there's to it. And it's directly caused by not raising an error earlier upon a non-200 response.
Backward compatibility for our current implementation.
Which code relies on a response other than 200, and actually works? My guess is: none whatsoever.
The RoboCJK RF extension just treats any error as "wrong credentials", which is also a symptom of this problem:
https://github.com/BlackFoundryCom/robo-cjk/blob/2e73fbb475a02ff6484d2c712d8c3a622ad204dd/sources/views/sheets.py#L885-L891
from django-robo-cjk.
API error responses already contain the error message, so we can just raise an exception using that message.
from django-robo-cjk.
Ah yes, this works nicely:
--- a/client.py
+++ b/client.py
@@ -7,6 +7,10 @@ import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+class HTTPError(Exception):
+ pass
+
+
class Client(object):
"""
@@ -107,6 +111,9 @@ class Client(object):
return self._api_call(view_name, params)
# read response json data and return dict
response_data = response.json()
+ if response.status_code != 200:
+ raise HTTPError(f"{response.status_code} {response_data['error']}")
+
return response_data
from django-robo-cjk.
I can make a PR if you want, after #5.
from django-robo-cjk.
Sure, PR would be appreciated!
from django-robo-cjk.
Related Issues (20)
- Layer name length limit of 50 characters is very low HOT 3
- Glyph and layer names can not contain chars > BMP HOT 2
- Split `return_related` option into `return_made_of` and `return_used_by` keeping backward compatibility.
- Feature request (for Fontra): add web API to return "modified since" glyph IDs for a font HOT 17
- Update RoboCJK APIs with timestamp capabilities.
- [api] Add server time to all API responses. HOT 10
- [admin] Add Font model inlines to Project admin.
- [import/export] Add admin settings for enable/disable import/export cronjob processes.
- Feature request: an option for xxx_lock and xxx_unlock to not return any glif data HOT 1
- Feature request: when calling glif_list with updated_since, also return the updated_at timestamps for each updated glyph HOT 2
- "update_at" and/or "layers_updated_at" should not be updated if the locking status changes
- Glyph locking should ideally not be done by user ID HOT 5
- Another "status" field bug when uploading glif data without status HOT 1
- automatic lock on glyph creation HOT 3
- Need a way to list glyphs that have been deleted since a timestamp HOT 5
- Multiple glyph encodings not included in in glif_list response HOT 9
- Add `pre-commit` and format all code with `Black`. HOT 1
- Add possibility to duplicate projects / fonts from the backend
- [logging] Send email notification in case of error.
- Replace Flake8 with Ruff.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-robo-cjk.