def METHOD_NAME(e, table_name):
    if (
        hasattr(e, "orig")
        and hasattr(e.orig, "pgerror")
        and e.orig.pgerror
        and ('duplicate key value violates unique constraint "ix_{}_service_id"'.format(table_name) in e.orig.pgerror)
    ):
        return (
            jsonify(
                result="error",
                message={"name": ["You can only have one URL and bearer token for your service."]},
            ),
            400,
        )
    elif (
        hasattr(e, "orig")
        and hasattr(e.orig, "pgerror")
        and e.orig.pgerror
        and (
            'insert or update on table "{0}" violates '
            'foreign key constraint "{0}_service_id_fkey"'.format(table_name) in e.orig.pgerror
        )
    ):
        return jsonify(result="error", message="No result found"), 404
    else:
        raise e