Flask Abort


The abort() function in Flask raises an HTTP exception for the given status code. It's helpful for exiting a view function when an error is detected

👇

@journal_api_blueprint.route('/<int:index>', methods=['GET'])
def get_journal_entry(index):

    ...

    # Check that the journal entry is associated with the current user
    if entry.user_id != user.id:
        abort(403)

    return entry