flask - Custom error handler in flask_restful throws NameError -


i trying add custom error code flask_restful api, following directions given in docs not receive correct response , getting nameerror: global name 'unsupportedmediatype' not defined message. doing wrong here?

# -*- coding: utf-8 -*-  flask import flask, request flask_restful import resource, api  import service  errors = {     'unsupportedmediatype': {         'message': 'unsupported media type',         'status': 415     } }  app = flask(__name__) api = api(app, errors=errors)  class service(resource):     def post(self):         if request.is_json:             data = request.get_json()             return service.handler(args['data'])         else:             raise unsupportedmediatype  api.add_resource(service, '/')  if __name__ == '__main__':     app.run(host='0.0.0.0', debug=true) 

you must store error handler function. this:

def error(exception): return {some json error data message 'exception'}

now can call error handler want.

or

you can use flask error handler decorator that. heres link


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -