Flask Abort for Json

April 28, 2019
from flask import jsonify, abort

def json_abort(status_code, message):
    data = {
        'error': {
            'code': status_code,
            'message': message
        }
    }
    response = jsonify(data)
    response.status_code = status_code
    abort(response)

NOTE: Compatiple format with Google API Design

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.