File tree Expand file tree Collapse file tree 6 files changed +32
-5
lines changed
Expand file tree Collapse file tree 6 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ Response marshalling
77
88
99Flask-RESTX provides an easy way to control what data you actually render in
10- your response or expect as in input payload.
10+ your response or expect as an input payload.
1111With the :mod: `~.fields ` module, you can use whatever objects (ORM
1212models/custom classes/etc.) you want in your resource.
1313:mod: `~.fields ` also lets you format and filter the response
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ Multiple namespaces
1616
1717There are many different ways to organize your Flask-RESTX app,
1818but here we'll describe one that scales pretty well with larger apps
19- and maintains a nice level organization.
19+ and maintains a nice level of organization.
2020
2121Flask-RESTX provides a way to use almost the same pattern as Flask's `blueprint `.
2222The main idea is to split your app into reusable namespaces.
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
2- __version__ = "0.2 .1.dev"
2+ __version__ = "0.3 .1.dev"
33__description__ = (
44 "Fully featured framework for fast, easy and documented API development with Flask"
55)
Original file line number Diff line number Diff line change @@ -677,7 +677,7 @@ def handle_error(self, e):
677677 if (
678678 not isinstance (e , HTTPException )
679679 and current_app .propagate_exceptions
680- and not isinstance (e , tuple (self .error_handlers .keys ()))
680+ and not isinstance (e , tuple (self ._own_and_child_error_handlers .keys ()))
681681 ):
682682
683683 exc_type , exc_value , tb = sys .exc_info ()
Original file line number Diff line number Diff line change 11{
22 "name" : " flask-restx" ,
3- "version" : " 0.2 .1.dev" ,
3+ "version" : " 0.3 .1.dev" ,
44 "description" : " Fully featured framework for fast, easy and documented API development with Flask" ,
55 "repository" : " python-restx/flask-restx" ,
66 "keywords" : [
Original file line number Diff line number Diff line change @@ -653,3 +653,30 @@ def handle_custom_exception(error):
653653 "message" : "error" ,
654654 "test" : "value" ,
655655 }
656+
657+ def test_namespace_errorhandler_with_propagate_true (self , app , client ):
658+ """Exceptions with errorhandler on a namespace should not be
659+ returned to client, even if PROPAGATE_EXCEPTIONS is set."""
660+ app .config ["PROPAGATE_EXCEPTIONS" ] = True
661+ api = restx .Api (app )
662+ namespace = restx .Namespace ('test_namespace' )
663+ api .add_namespace (namespace )
664+
665+ @namespace .route ("/test/" , endpoint = "test" )
666+ class TestResource (restx .Resource ):
667+ def get (self ):
668+ raise RuntimeError ("error" )
669+
670+ @namespace .errorhandler (RuntimeError )
671+ def handle_custom_exception (error ):
672+ return {"message" : str (error ), "test" : "value" }, 400
673+
674+ response = client .get ("/test_namespace/test/" )
675+ assert response .status_code == 400
676+ assert response .content_type == "application/json"
677+
678+ data = json .loads (response .data .decode ("utf8" ))
679+ assert data == {
680+ "message" : "error" ,
681+ "test" : "value" ,
682+ }
You can’t perform that action at this time.
0 commit comments