If we made [AirflowNotFound](https://github.com/apache/airflow/blob/master/airflow/exceptions.py#L43-L46) inherit from [connextion.NotFound](https://github.com/apache/airflow/blob/master/airflow/api_connexion/exceptions.py#L75-L83) this code could be a simpler [here](https://github.com/apache/airflow/blob/690e80b82b12ab1d7232d6f02ea6bddd1d71750c/airflow/api_connexion/endpoints/task_instance_endpoint.py#L290-L297).


_Originally posted by @ashb in https://github.com/apache/airflow/pull/11335#discussion_r511863077_
airflow/api_connexion/endpoints/task_instance_endpoint.py
@security.requires_access(
    [
        (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG),
        (permissions.ACTION_CAN_READ, permissions.RESOURCE_DAG_RUN),
        (permissions.ACTION_CAN_READ, permissions.RESOURCE_TASK_INSTANCE),
    ]
)
@provide_session
def get_task_instance(dag_id: str, dag_run_id: str, task_id: str, session=None):
    """Get task instance"""
    query = (
        session.query(TI)
        .filter(TI.dag_id == dag_id, DR.run_id == dag_run_id, TI.task_id == task_id)
        .join(TI.dag_run)
        .options(eagerload(TI.dag_run))
        .outerjoin(
            SlaMiss,
            and_(
                SlaMiss.dag_id == TI.dag_id,
                SlaMiss.execution_date == DR.execution_date,
                SlaMiss.task_id == TI.task_id,
            ),
        )
        .add_entity(SlaMiss)
    )
    task_instance = query.one_or_none()
    if task_instance is None:
        raise NotFound("Task instance not found")
    return task_instance_schema.dump(task_instance)
def _apply_array_filter(query, key, values):