File tree Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Expand file tree Collapse file tree 2 files changed +10
-3
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
2
3
- from flask import Flask
3
+ from flask import Flask , jsonify
4
4
from flask_restful import Api
5
- from flask_jwt import JWT
5
+ import flask_jwt
6
6
7
7
from security import authenticate , identity
8
8
from resources .user import UserRegister
15
15
16
16
app .config ['SQLALCHEMY_DATABASE_URI' ] = os .environ .get ('DATABASE_URL' , 'sqlite:///data.db' )
17
17
app .config ['SQLALCHEMY_TRACK_MODIFICATIONS' ] = False
18
+ app .config ['PROPAGATE_EXCEPTIONS' ] = True
18
19
app .secret_key = 'jose'
19
20
api = Api (app )
20
21
21
- jwt = JWT (app , authenticate , identity ) # /auth
22
+ jwt = flask_jwt . JWT (app , authenticate , identity ) # /auth
22
23
23
24
api .add_resource (Store , '/store/<string:name>' )
24
25
api .add_resource (Item , '/item/<string:name>' )
27
28
28
29
api .add_resource (UserRegister , '/register' )
29
30
31
+
32
+ @app .errorhandler (flask_jwt .JWTError )
33
+ def auth_error (err ):
34
+ return jsonify ({'message' : 'Could not authorize. Did you include a valid Authorization header?' }), 401
35
+
30
36
if __name__ == '__main__' :
31
37
from db import db
32
38
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ class BaseTest(TestCase):
17
17
@classmetho
58C4
d
18
18
def setUpClass (cls ):
19
19
app .config ['SQLALCHEMY_DATABASE_URI' ] = BaseTest .SQLALCHEMY_DATABASE_URI
20
+ app .config ['DEBUG' ] = False
20
21
with app .app_context ():
21
22
db .init_app (app )
22
23
You can’t perform that action at this time.
0 commit comments