<?php

namespace Ojs\JournalBundle\Entity;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;

/**
 * ArticleFileRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ArticleFileRepository extends EntityRepository
{

    /**
     * Get Article full text file.
     * @param  integer                   $articleId
     * @return ArticleFile[]
     * @throws UsernameNotFoundException
     */
    public function getArticleFullTextFiles($articleId)
    {
        try {
            $article = $this
                ->getEntityManager()
                ->getRepository('OjsJournalBundle:Article')
                ->find($articleId);

            if (!$article) {
                throw new NoResultException();
            }

            $q = $this
                ->createQueryBuilder('a')
                ->select('a')
                ->where('a.article = :article AND a.type= 0')
                ->setParameter('article', $article)
                ->getQuery();

            // The Query::getResult() method throws an exception
            // if there is no record matching the criteria.
            return $q->getResult();
        } catch (NoResultException $e) {
            $message = sprintf('There is no full text file for this article.');
            throw new UsernameNotFoundException($message, 0, $e); // TODO: UsernameNotFoundException?!
        }
    }
}

<?php

namespace Ojs\JournalBundle\Entity;

use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\NoResultException;

/**
 * ArticleFileRepository
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class ArticleFileRepository extends EntityRepository
{
    /**
     * Get Article full text file.
     * @param  integer $articleId
     * @return ArticleFile[]
     * @throws NoResultException
     */
    public function getArticleFullTextFiles($articleId)
    {
        try {
            $article = $this
                ->getEntityManager()
                ->getRepository('OjsJournalBundle:Article')
                ->find($articleId);

            if (!$article) {
                throw new NoResultException();
            }

            $q = $this
                ->createQueryBuilder('a')
                ->select('a')
                ->where('a.article = :article AND a.type= 0')
                ->setParameter('article', $article)
                ->getQuery();

            // The Query::getResult() method throws an exception
            // if there is no record matching the criteria.
            return $q->getResult();
        } catch (NoResultException $e) {
            $message = sprintf('There is no full text file for this article.');
            throw new NoResultException($message, 0, $e);
        }
    }
}

Change the exception with a more sensible one
Change the exception with a more sensible one
