Skip to content

Commit

Permalink
Update python_component.md
Browse files Browse the repository at this point in the history
  • Loading branch information
klalit committed Jun 26, 2019
1 parent b994f82 commit 968242f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions doc/source/python/python_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ If you want to handle custom exceptions define a field `model_error_handler` as
```
An example is as follow:

```
```python
"""
Model Template
"""
class MyModel(Object):

#The field that can be used to register custom exceptions
"""
The field is used to register custom exceptions
"""
model_error_handler = flask.Blueprint('error_handlers', __name__)

#Register the handler for an exception
"""
Register the handler for an exception
"""
@model_error_handler.app_errorhandler(UserCustomException)
def handleCustomError(error):
response = jsonify(error.to_dict())
Expand All @@ -192,7 +199,10 @@ class MyModel(Object):
return X
```

```
```python
"""
User Defined Exception
"""
class UserCustomException(Exception):

status_code = 404
Expand Down

0 comments on commit 968242f

Please sign in to comment.