mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Import werkzeug exceptions wholesale
This commit is contained in:
parent
28f6371ae1
commit
bc5f8c7751
@ -5,8 +5,7 @@ from flask import Flask
|
||||
from flask import jsonify
|
||||
from flask import request
|
||||
from flask.views import MethodView
|
||||
from werkzeug.exceptions import default_exceptions
|
||||
from werkzeug.exceptions import HTTPException
|
||||
from werkzeug import exceptions
|
||||
|
||||
import salt.client
|
||||
import salt.runner
|
||||
@ -36,7 +35,8 @@ def make_json_error(ex):
|
||||
|
||||
'''
|
||||
response = jsonify(message=str(ex))
|
||||
response.status_code = (ex.code if isinstance(ex, HTTPException) else 500)
|
||||
response.status_code = (ex.code
|
||||
if isinstance(ex, exceptions.HTTPException) else 500)
|
||||
return response
|
||||
|
||||
class SaltAPI(MethodView):
|
||||
@ -92,7 +92,7 @@ def build_app():
|
||||
app = Flask('rest_flask')
|
||||
jobs = JobsView.as_view('jobs')
|
||||
|
||||
for code in default_exceptions.iterkeys():
|
||||
for code in exceptions.default_exceptions.iterkeys():
|
||||
app.error_handler_spec[None][code] = make_json_error
|
||||
|
||||
app.add_url_rule('/jobs', view_func=jobs, methods=['GET', 'POST'])
|
||||
|
Loading…
Reference in New Issue
Block a user