You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: Hide parsed_exception property, expose only convenience properties
Based on user feedback, direct access to parsed_exception has been hidden
to provide a cleaner, more intentional API design.
Changes:
- exceptions.py: parsed_exception getter now raises AttributeError with helpful message
- exceptions.py: parsed_exception setter kept for internal use by api_client
- Convenience properties (code, error_message, etc.) remain fully functional
- Tests updated to use convenience properties instead of parsed_exception
- Documentation updated to remove parsed_exception examples
Design rationale:
- Encourages using cleaner convenience properties (e.code, e.error_message)
- Prevents users from accessing internal parsed response object
- Setter still works for api_client.py to populate error details internally
- More intentional API surface with better user experience
User Impact:
- Code using e.parsed_exception.code will need to change to e.code
- Code using e.header.get('fga-request-id') continues to work
- All convenience properties work as before
Tests: 17 unit tests passing
@@ -159,18 +158,19 @@ All `ApiException` instances now have these methods:
159
158
160
159
## Backward Compatibility
161
160
162
-
All changes are **fully backward compatible**. Existing code continues to work without modifications:
161
+
The convenience properties and helper methods are new additions. Existing code using header dictionaries continues to work:
163
162
164
163
```python
165
164
# Old code still works
166
165
try:
167
166
client.check(...)
168
167
except ApiException as e:
169
-
if e.parsed_exception:
170
-
code = e.parsed_exception.code # Still works!
171
168
request_id = e.header.get('fga-request-id') # Still works!
169
+
store_id = e.header.get('store_id') # Still works!
172
170
```
173
171
172
+
**Note:** Direct access to `parsed_exception` has been intentionally hidden to encourage using the cleaner convenience properties (`e.code`, `e.error_message`, etc.).
173
+
174
174
## Testing
175
175
176
176
### Unit Tests
@@ -260,12 +260,12 @@ No migration needed! But you can improve your existing code:
260
260
261
261
### Quick Wins
262
262
263
-
1.**Replace nested access with properties:**
263
+
1.**Use convenience properties instead of header dict:**
264
264
```python
265
265
# Before
266
-
code= e.parsed_exception.code if e.parsed_exception elseNone
266
+
request_id= e.header.get('fga-request-id')
267
267
# After
268
-
code= e.code
268
+
request_id= e.request_id
269
269
```
270
270
271
271
2.**Use helper methods instead of type checks:**
@@ -303,11 +303,11 @@ No migration needed! But you can improve your existing code:
303
303
304
304
### Design Principles
305
305
306
-
-**Backward Compatibility:** All existing code continues to work
307
-
-**No Breaking Changes:** Only additive changes
306
+
-**Clean API:** Direct access to `parsed_exception` is hidden to encourage using convenience properties
308
307
-**Pythonic:** Uses properties and methods, not nested data structures
309
308
-**Type Safe:** All properties and methods properly typed
310
309
-**Well Tested:** 17 unit tests + integration tests
310
+
-**Internal Compatibility:** api_client can still set `parsed_exception` internally
0 commit comments